1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use crate::{Growth, SplitVec};
use orx_pinned_vec::PinnedVec;

impl<T, G: Growth> FromIterator<T> for SplitVec<T, G>
where
    SplitVec<T, G>: Default,
{
    fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
        let mut vec = Self::default();
        for i in iter {
            vec.push(i)
        }
        vec
    }
}

#[cfg(test)]
mod tests {
    use crate::{Doubling, Recursive, SplitVec};

    #[test]
    fn collect() {
        let vec = SplitVec::<_, Doubling>::from_iter([0, 1, 2, 3, 4, 5]);
        assert_eq!(&vec, &[0, 1, 2, 3, 4, 5]);

        let vec = SplitVec::<_>::from_iter([0, 1, 2, 3, 4, 5]);
        assert_eq!(&vec, &[0, 1, 2, 3, 4, 5]);

        let vec: SplitVec<_, Doubling> = (0..6).collect();
        assert_eq!(&vec, &[0, 1, 2, 3, 4, 5]);

        let vec: SplitVec<_, Recursive> = (0..6).collect();
        assert_eq!(&vec, &[0, 1, 2, 3, 4, 5]);

        let vec: SplitVec<_> = (0..6).collect();
        assert_eq!(&vec, &[0, 1, 2, 3, 4, 5]);

        let vec: SplitVec<_> = (0..6).filter(|x| x % 2 == 0).collect();
        assert_eq!(&vec, &[0, 2, 4]);

        let vec: SplitVec<_, Doubling> = (0..6).filter(|x| x % 2 == 0).collect();
        assert_eq!(&vec, &[0, 2, 4]);

        let vec: SplitVec<_, Recursive> = (0..6).filter(|x| x % 2 == 0).collect();
        assert_eq!(&vec, &[0, 2, 4]);
    }
}