mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Simplify AppendOnlyVec iterators
This commit is contained in:
@@ -46,20 +46,17 @@ pub fn get(&self, i: usize) -> Option<T> {
|
||||
}
|
||||
|
||||
pub fn iter_enumerated(&self) -> impl Iterator<Item = (usize, T)> {
|
||||
(0..)
|
||||
.map(|i| (i, self.get(i)))
|
||||
.take_while(|(_, o)| o.is_some())
|
||||
.filter_map(|(i, o)| Some((i, o?)))
|
||||
(0..).map_while(|i| Some((i, self.get(i)?)))
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = T> {
|
||||
(0..).map(|i| self.get(i)).take_while(|o| o.is_some()).flatten()
|
||||
(0..).map_while(|i| self.get(i))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy + PartialEq> AppendOnlyVec<T> {
|
||||
pub fn contains(&self, val: T) -> bool {
|
||||
self.iter_enumerated().any(|(_, v)| v == val)
|
||||
self.iter().any(|v| v == val)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user