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)]
|
||||
#![allow(rustc::default_hash_types)]
|
||||
#![deny(unaligned_references)]
|
||||
#![feature(iter_map_while)]
|
||||
#![feature(bool_to_option)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
@ -86,10 +86,10 @@ pub fn get_by_key(&'a self, key: K) -> impl 'a + Iterator<Item = &'a V> {
|
||||
/// insertion order.
|
||||
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);
|
||||
self.idx_sorted_by_item_key[lower_bound..]
|
||||
.iter()
|
||||
.take_while(move |&&i| self.items[i].0.eq(&key))
|
||||
.map(move |&idx| (idx, &self.items[idx].1))
|
||||
self.idx_sorted_by_item_key[lower_bound..].iter().map_while(move |&i| {
|
||||
let (k, v) = &self.items[i];
|
||||
(k == &key).then_some((i, v))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user