cl_generic_vec/
iter.rs

1//! The [`Iterator`] types that can be created from a [`GenericVec`]
2
3mod cursor;
4mod drain;
5mod drain_filter;
6mod into_iter;
7mod raw_cursor;
8mod splice;
9
10pub use cursor::Cursor;
11pub use drain::Drain;
12pub use drain_filter::DrainFilter;
13pub use into_iter::IntoIter;
14pub use raw_cursor::RawCursor;
15pub use splice::Splice;
16
17use core::iter::FromIterator;
18
19use crate::{
20    raw::{Storage, StorageWithCapacity},
21    SimpleVec,
22};
23
24impl<V, S: StorageWithCapacity + Default> FromIterator<V> for SimpleVec<S>
25where
26    Self: Extend<V>,
27{
28    #[inline]
29    fn from_iter<I: IntoIterator<Item = V>>(iter: I) -> Self {
30        let mut array = Self::default();
31        array.extend(iter);
32        array
33    }
34}
35
36impl<S: ?Sized + Storage> Extend<S::Item> for SimpleVec<S> {
37    fn extend<I: IntoIterator<Item = S::Item>>(&mut self, iter: I) {
38        let iter = iter.into_iter();
39        let _ = self.try_reserve(iter.size_hint().0);
40        #[allow(clippy::drop_ref)]
41        iter.for_each(|item| drop(self.push(item)));
42    }
43}