pub struct Defer(Option); impl Defer { pub fn new(f: F) -> Self { Defer(Some(f)) } } impl Drop for Defer { fn drop(&mut self) { if let Some(f) = self.0.take() { f(); } } }