use crate::types::NativeType;
use std::mem::ManuallyDrop;
use std::ops::{Deref, DerefMut};
pub(super) struct MaybeForeign<T: NativeType> {
inner: ManuallyDrop<Vec<T>>,
}
impl<T: NativeType> MaybeForeign<T> {
#[inline]
pub(super) fn new(data: Vec<T>) -> Self {
Self {
inner: ManuallyDrop::new(data),
}
}
#[inline]
pub(super) unsafe fn drop_local(&mut self) {
let data = std::mem::take(&mut self.inner);
let _data = ManuallyDrop::into_inner(data);
}
#[inline]
pub(super) unsafe fn mut_vec(&mut self) -> &mut Vec<T> {
self.inner.deref_mut()
}
}
impl<T: NativeType> Deref for MaybeForeign<T> {
type Target = [T];
#[inline]
fn deref(&self) -> &Self::Target {
&self.inner
}
}