#[macro_export] macro_rules! invoke_once { () => { unsafe { static mut __VALUE: bool = false; if __VALUE { false } else { __VALUE = true; true } } }; // if this is used inside of an unsafe codeblock // use this branch to avoid the unnecessary unsafe block warning (unsafe) => { { static mut __VALUE: bool = false; if __VALUE { false } else { __VALUE = true; true } } } } pub struct OnDrop(Option); impl OnDrop { pub fn new(fun: F) -> Self { Self(Some(fun)) } } impl Drop for OnDrop { fn drop(&mut self) { if let Some(fun) = self.0.take() { fun() } } }