Skip to content

Commit b5c64e2

Browse files
committed
Clarify docs for when binary_search has many matches.
Fixes #51817.
1 parent 1886d5f commit b5c64e2

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
@@ -1174,9 +1174,10 @@ impl<T> [T] {
11741174

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

0 commit comments

Comments
 (0)