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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use crate::ImpVec;
use orx_fixed_vec::FixedVec;
use orx_split_vec::{SplitVec, SplitVecGrowth};

impl<T> From<ImpVec<T, FixedVec<T>>> for FixedVec<T> {
    fn from(value: ImpVec<T, FixedVec<T>>) -> Self {
        value.cell.into_inner()
    }
}

impl<T, G> From<ImpVec<T, SplitVec<T, G>>> for SplitVec<T, G>
where
    G: SplitVecGrowth<T>,
{
    fn from(value: ImpVec<T, SplitVec<T, G>>) -> Self {
        value.cell.into_inner()
    }
}

#[cfg(test)]
mod tests {
    use crate::prelude::*;
    use crate::test_all_growth_types;

    #[test]
    fn into_split_vec() {
        fn test<G: SplitVecGrowth<usize>>(mut pinned_vec: SplitVec<usize, G>) {
            for i in 0..400 {
                pinned_vec.push(i * 2);
            }

            let imp: ImpVec<_, _> = pinned_vec.into();
            for i in 400..1000 {
                imp.push(i * 2);
            }

            let expected: Vec<_> = (0..1000).map(|i| i * 2).collect();

            assert_eq!(expected, imp);

            let pinned_back: SplitVec<usize, G> = imp.into();
            assert_eq!(expected, pinned_back);
        }

        test_all_growth_types!(test);
    }

    #[test]
    fn into_fixed_vec() {
        let mut pinned_vec = FixedVec::new(1000);

        for i in 0..400 {
            pinned_vec.push(i * 2);
        }

        let imp: ImpVec<_, _> = pinned_vec.into();
        for i in 400..1000 {
            imp.push(i * 2);
        }

        let expected: Vec<_> = (0..1000).map(|i| i * 2).collect();

        assert_eq!(expected, imp);

        let pinned_back: FixedVec<usize> = imp.into();
        assert_eq!(pinned_back, expected);
    }
}