aboutsummaryrefslogtreecommitdiff
path: root/src/rust_vec.rs
blob: 4c5035d66031af27664c15c5aab751bb9c01e837 (plain)
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
#[repr(C)]
pub struct RustVec<T> {
    repr: Vec<T>,
}

impl<T> RustVec<T> {
    pub fn new() -> Self {
        RustVec { repr: Vec::new() }
    }

    pub fn from(v: Vec<T>) -> Self {
        RustVec { repr: v }
    }

    pub fn from_ref(v: &Vec<T>) -> &Self {
        unsafe { &*(v as *const Vec<T> as *const RustVec<T>) }
    }

    pub fn into_vec(self) -> Vec<T> {
        self.repr
    }

    pub fn as_vec(&self) -> &Vec<T> {
        &self.repr
    }

    pub fn as_mut_vec(&mut self) -> &mut Vec<T> {
        &mut self.repr
    }

    pub fn len(&self) -> usize {
        self.repr.len()
    }

    pub fn as_ptr(&self) -> *const T {
        self.repr.as_ptr()
    }
}