orx_concurrent_vec/
to_vec.rs

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
use crate::{elem::ConcurrentElement, ConcurrentVec};
use alloc::vec::Vec;
use orx_pinned_vec::IntoConcurrentPinnedVec;

impl<T, P> ConcurrentVec<T, P>
where
    P: IntoConcurrentPinnedVec<ConcurrentElement<T>>,
{
    /// Transforms the concurrent vec into a regular vector.
    pub fn to_vec(self) -> Vec<T> {
        let pinned = self.into_inner();
        let mut vec = Vec::with_capacity(pinned.len());
        for x in pinned {
            vec.push(x.0.expect("unwrapped none"));
        }
        vec
    }

    /// Without consuming the concurrent vector,
    /// clones the values of its elements into a regular vector.
    pub fn clone_to_vec(&self) -> Vec<T>
    where
        T: Clone,
    {
        self.as_slice().clone_to_vec()
    }
}