Use map_while
instead of take_while
+ map
This commit is contained in:
parent
cb3b3cf6ab
commit
8d00be9980
@ -27,6 +27,8 @@
|
|||||||
#![feature(min_type_alias_impl_trait)]
|
#![feature(min_type_alias_impl_trait)]
|
||||||
#![allow(rustc::default_hash_types)]
|
#![allow(rustc::default_hash_types)]
|
||||||
#![deny(unaligned_references)]
|
#![deny(unaligned_references)]
|
||||||
|
#![feature(iter_map_while)]
|
||||||
|
#![feature(bool_to_option)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate tracing;
|
extern crate tracing;
|
||||||
|
@ -86,10 +86,10 @@ pub fn get_by_key(&'a self, key: K) -> impl 'a + Iterator<Item = &'a V> {
|
|||||||
/// insertion order.
|
/// insertion order.
|
||||||
pub fn get_by_key_enumerated(&'a self, key: K) -> impl '_ + Iterator<Item = (I, &V)> {
|
pub fn get_by_key_enumerated(&'a self, key: K) -> impl '_ + Iterator<Item = (I, &V)> {
|
||||||
let lower_bound = self.idx_sorted_by_item_key.partition_point(|&i| self.items[i].0 < key);
|
let lower_bound = self.idx_sorted_by_item_key.partition_point(|&i| self.items[i].0 < key);
|
||||||
self.idx_sorted_by_item_key[lower_bound..]
|
self.idx_sorted_by_item_key[lower_bound..].iter().map_while(move |&i| {
|
||||||
.iter()
|
let (k, v) = &self.items[i];
|
||||||
.take_while(move |&&i| self.items[i].0.eq(&key))
|
(k == &key).then_some((i, v))
|
||||||
.map(move |&idx| (idx, &self.items[idx].1))
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user