aboutsummaryrefslogtreecommitdiff
path: root/crates/stdx/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-01-07 22:39:02 +0000
committerAleksey Kladov <[email protected]>2021-01-08 20:47:35 +0000
commite30c1c3fbf8f70336d985b2b73e5b0f45f3b95f5 (patch)
treea3cdc2d2f667ab5a122758152eb338a654d387cd /crates/stdx/src
parent981a0d708ec352969f9ca075a3e0e50c6da48197 (diff)
Simplify highlighting infra
This also fixes the killer whale bug
Diffstat (limited to 'crates/stdx/src')
-rw-r--r--crates/stdx/src/lib.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs
index 5332edb09..5aacdb16e 100644
--- a/crates/stdx/src/lib.rs
+++ b/crates/stdx/src/lib.rs
@@ -1,5 +1,5 @@
1//! Missing batteries for standard libraries. 1//! Missing batteries for standard libraries.
2use std::{ops, process, time::Instant}; 2use std::{cmp::Ordering, ops, process, time::Instant};
3 3
4mod macros; 4mod macros;
5pub mod panic_context; 5pub mod panic_context;
@@ -117,7 +117,12 @@ impl<'a> Iterator for LinesWithEnds<'a> {
117 } 117 }
118} 118}
119 119
120// https://github.com/rust-lang/rust/issues/73831 120/// Returns `idx` such that:
121///
122/// ∀ x in slice[..idx]: pred(x)
123/// && ∀ x in slice[idx..]: !pred(x)
124///
125/// https://github.com/rust-lang/rust/issues/73831
121pub fn partition_point<T, P>(slice: &[T], mut pred: P) -> usize 126pub fn partition_point<T, P>(slice: &[T], mut pred: P) -> usize
122where 127where
123 P: FnMut(&T) -> bool, 128 P: FnMut(&T) -> bool,
@@ -147,6 +152,15 @@ where
147 left 152 left
148} 153}
149 154
155pub fn equal_range_by<T, F>(slice: &[T], mut key: F) -> (usize, usize)
156where
157 F: FnMut(&T) -> Ordering,
158{
159 let start = partition_point(slice, |it| key(it) == Ordering::Less);
160 let len = partition_point(&slice[start..], |it| key(it) == Ordering::Equal);
161 (start, len)
162}
163
150pub struct JodChild(pub process::Child); 164pub struct JodChild(pub process::Child);
151 165
152impl ops::Deref for JodChild { 166impl ops::Deref for JodChild {