use core::{cell::UnsafeCell, mem::ManuallyDrop}; pub fn unit(_: T) {} pub struct DropGuard(UnsafeCell>); impl DropGuard where F: FnOnce(), { pub fn new(f: F) -> DropGuard { Self(UnsafeCell::new(ManuallyDrop::new(f))) } } impl Drop for DropGuard where F: FnOnce(), { fn drop(&mut self) { unsafe { ManuallyDrop::take(&mut *self.0.get())(); } } }