-#[repr(C)]
-pub struct CVecTempl<T> {
- pub data: *mut T,
- pub datalen: usize
-}
-impl<T> CVecTempl<T> {
- pub(crate) fn into_rust(&mut self) -> Vec<T> {
- if self.datalen == 0 { return Vec::new(); }
- let ret = unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }.into();
- self.data = std::ptr::null_mut();
- self.datalen = 0;
- ret
- }
- pub(crate) fn as_slice(&self) -> &[T] {
- unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) }
- }
-}
-impl<T> From<Vec<T>> for CVecTempl<T> {
- fn from(v: Vec<T>) -> Self {
- let datalen = v.len();
- let data = Box::into_raw(v.into_boxed_slice());
- CVecTempl { datalen, data: unsafe { (*data).as_mut_ptr() } }
- }
-}
-pub extern "C" fn CVecTempl_free<T>(_res: CVecTempl<T>) { }
-impl<T> Drop for CVecTempl<T> {
- fn drop(&mut self) {
- if self.datalen == 0 { return; }
- unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) };
- }
-}
-impl<T: Clone> Clone for CVecTempl<T> {
- fn clone(&self) -> Self {
- let mut res = Vec::new();
- if self.datalen == 0 { return Self::from(res); }
- res.extend_from_slice(unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) });
- Self::from(res)
- }
-}
-