diff options
author | Aleksey Kladov <[email protected]> | 2021-01-07 22:39:02 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-01-08 20:47:35 +0000 |
commit | e30c1c3fbf8f70336d985b2b73e5b0f45f3b95f5 (patch) | |
tree | a3cdc2d2f667ab5a122758152eb338a654d387cd /crates/stdx/src | |
parent | 981a0d708ec352969f9ca075a3e0e50c6da48197 (diff) |
Simplify highlighting infra
This also fixes the killer whale bug
Diffstat (limited to 'crates/stdx/src')
-rw-r--r-- | crates/stdx/src/lib.rs | 18 |
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. |
2 | use std::{ops, process, time::Instant}; | 2 | use std::{cmp::Ordering, ops, process, time::Instant}; |
3 | 3 | ||
4 | mod macros; | 4 | mod macros; |
5 | pub mod panic_context; | 5 | pub 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 | ||
121 | pub fn partition_point<T, P>(slice: &[T], mut pred: P) -> usize | 126 | pub fn partition_point<T, P>(slice: &[T], mut pred: P) -> usize |
122 | where | 127 | where |
123 | P: FnMut(&T) -> bool, | 128 | P: FnMut(&T) -> bool, |
@@ -147,6 +152,15 @@ where | |||
147 | left | 152 | left |
148 | } | 153 | } |
149 | 154 | ||
155 | pub fn equal_range_by<T, F>(slice: &[T], mut key: F) -> (usize, usize) | ||
156 | where | ||
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 | |||
150 | pub struct JodChild(pub process::Child); | 164 | pub struct JodChild(pub process::Child); |
151 | 165 | ||
152 | impl ops::Deref for JodChild { | 166 | impl ops::Deref for JodChild { |