use super::*;
#[derive(Debug)]
pub struct DropHandle<T: DropMoveTypes>(ManuallyDrop<T::Outer>);
impl<T: DropMoveTypes> DropHandle<T> {
unsafe fn take(self_: &mut Self) -> T::Outer {
ManuallyDrop::take(&mut self_.0)
}
pub fn into_inner(self_: Self) -> T {
Self::into_outer(self_).into()
}
pub fn into_outer(mut self_: Self) -> T::Outer {
let outer = unsafe { Self::take(&mut self_) };
mem::forget(self_);
outer
}
}
impl<T: DropMoveTypes> From<T> for DropHandle<T> {
fn from(t: T) -> Self {
Self(ManuallyDrop::new(t.into()))
}
}
impl<T: DropMoveTypes> Drop for DropHandle<T> {
fn drop(&mut self) {
let _inner: T = unsafe { Self::take(self) }.into();
}
}
impl<T: DropMoveTypes> Deref for DropHandle<T> {
type Target = T::Outer;
fn deref(&self) -> &T::Outer {
self.0.deref()
}
}
impl<T: DropMoveTypes> DerefMut for DropHandle<T> {
fn deref_mut(&mut self) -> &mut T::Outer {
self.0.deref_mut()
}
}