@@ -2359,6 +2359,28 @@ impl<T> [T] {
23592359 /// assert!(match r { Ok(1..=4) => true, _ => false, });
23602360 /// ```
23612361 ///
2362+ /// If you want to find that whole *range* of matching items, rather than
2363+ /// an arbitrary matching one, that can be done using [`partition_point`]:
2364+ /// ```
2365+ /// let s = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
2366+ ///
2367+ /// let low = s.partition_point(|x| x < &1);
2368+ /// assert_eq!(low, 1);
2369+ /// let high = s.partition_point(|x| x <= &1);
2370+ /// assert_eq!(high, 5);
2371+ /// let r = s.binary_search(&1);
2372+ /// assert!((low..high).contains(&r.unwrap()));
2373+ ///
2374+ /// assert!(s[..low].iter().all(|&x| x < 1));
2375+ /// assert!(s[low..high].iter().all(|&x| x == 1));
2376+ /// assert!(s[high..].iter().all(|&x| x > 1));
2377+ ///
2378+ /// // For something not found, the "range" of equal items is empty
2379+ /// assert_eq!(s.partition_point(|x| x < &11), 9);
2380+ /// assert_eq!(s.partition_point(|x| x <= &11), 9);
2381+ /// assert_eq!(s.binary_search(&11), Err(9));
2382+ /// ```
2383+ ///
23622384 /// If you want to insert an item to a sorted vector, while maintaining
23632385 /// sort order, consider using [`partition_point`]:
23642386 ///
@@ -3778,6 +3800,16 @@ impl<T> [T] {
37783800 /// assert!(v[i..].iter().all(|&x| !(x < 5)));
37793801 /// ```
37803802 ///
3803+ /// If all elements of the slice match the predicate, including if the slice
3804+ /// is empty, then the length of the slice will be returned:
3805+ ///
3806+ /// ```
3807+ /// let a = [2, 4, 8];
3808+ /// assert_eq!(a.partition_point(|x| x < &100), a.len());
3809+ /// let a: [i32; 0] = [];
3810+ /// assert_eq!(a.partition_point(|x| x < &100), 0);
3811+ /// ```
3812+ ///
37813813 /// If you want to insert an item to a sorted vector, while maintaining
37823814 /// sort order:
37833815 ///
0 commit comments