//! A drop implementation runner. /// Runs a closure on drop. pub struct OnDrop { f: core::mem::MaybeUninit, } impl OnDrop { /// Make a new droppper given a closure. pub fn new(f: F) -> Self { Self { f: core::mem::MaybeUninit::new(f), } } /// Make it not run drop. pub fn defuse(self) { core::mem::forget(self) } } impl Drop for OnDrop { fn drop(&mut self) { unsafe { self.f.as_ptr().read()() } } }