blob: a8a144a32ac5118125a53d4abbf7db10303d74c4 [file] [log] [blame]
Myron Ahneba35cf2020-02-05 19:41:51 +07001#[repr(C)]
David Tolnay3a8ae092020-04-24 11:55:46 -07002pub struct RustVec<T> {
Myron Ahneba35cf2020-02-05 19:41:51 +07003 repr: Vec<T>,
4}
5
David Tolnay3a8ae092020-04-24 11:55:46 -07006impl<T> RustVec<T> {
Myron Ahneba35cf2020-02-05 19:41:51 +07007 pub fn from(v: Vec<T>) -> Self {
8 RustVec { repr: v }
9 }
10
11 pub fn from_ref(v: &Vec<T>) -> &Self {
David Tolnayfac8b252020-04-24 11:37:39 -070012 unsafe { &*(v as *const Vec<T> as *const RustVec<T>) }
Myron Ahneba35cf2020-02-05 19:41:51 +070013 }
14
15 pub fn into_vec(self) -> Vec<T> {
16 self.repr
17 }
18
19 pub fn as_vec(&self) -> &Vec<T> {
20 &self.repr
21 }
22
23 pub fn as_mut_vec(&mut self) -> &mut Vec<T> {
24 &mut self.repr
25 }
26
27 pub fn len(&self) -> usize {
28 self.repr.len()
29 }
Myron Ahneba35cf2020-02-05 19:41:51 +070030}