Skip to content

Commit ef5c00d

Browse files
committed
Auto merge of #54700 - frewsxcv:frewsxcv-binary-search, r=GuillaumeGomez
Clarify docs for when binary_search has many matches. Fixes #51817.
2 parents aefe9b0 + b5c64e2 commit ef5c00d

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

Diff for: src/libcore/slice/mod.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -1175,9 +1175,10 @@ impl<T> [T] {
11751175

11761176
/// Binary searches this sorted slice for a given element.
11771177
///
1178-
/// If the value is found then `Ok` is returned, containing the
1179-
/// index of the matching element; if the value is not found then
1180-
/// `Err` is returned, containing the index where a matching
1178+
/// If the value is found then [`Result::Ok`] is returned, containing the
1179+
/// index of the matching element. If there are multiple matches, then any
1180+
/// one of the matches could be returned. If the value is not found then
1181+
/// [`Result::Err`] is returned, containing the index where a matching
11811182
/// element could be inserted while maintaining sorted order.
11821183
///
11831184
/// # Examples
@@ -1209,9 +1210,10 @@ impl<T> [T] {
12091210
/// order code that indicates whether its argument is `Less`,
12101211
/// `Equal` or `Greater` the desired target.
12111212
///
1212-
/// If a matching value is found then returns `Ok`, containing
1213-
/// the index for the matched element; if no match is found then
1214-
/// `Err` is returned, containing the index where a matching
1213+
/// If the value is found then [`Result::Ok`] is returned, containing the
1214+
/// index of the matching element. If there are multiple matches, then any
1215+
/// one of the matches could be returned. If the value is not found then
1216+
/// [`Result::Err`] is returned, containing the index where a matching
12151217
/// element could be inserted while maintaining sorted order.
12161218
///
12171219
/// # Examples
@@ -1265,10 +1267,11 @@ impl<T> [T] {
12651267
/// Assumes that the slice is sorted by the key, for instance with
12661268
/// [`sort_by_key`] using the same key extraction function.
12671269
///
1268-
/// If a matching value is found then returns `Ok`, containing the
1269-
/// index for the matched element; if no match is found then `Err`
1270-
/// is returned, containing the index where a matching element could
1271-
/// be inserted while maintaining sorted order.
1270+
/// If the value is found then [`Result::Ok`] is returned, containing the
1271+
/// index of the matching element. If there are multiple matches, then any
1272+
/// one of the matches could be returned. If the value is not found then
1273+
/// [`Result::Err`] is returned, containing the index where a matching
1274+
/// element could be inserted while maintaining sorted order.
12721275
///
12731276
/// [`sort_by_key`]: #method.sort_by_key
12741277
///

0 commit comments

Comments
 (0)