This commit is contained in:
2024-01-30 02:09:24 -05:00
parent 224bd7a699
commit 760e36bdb1
2 changed files with 22 additions and 0 deletions

View File

@@ -18,3 +18,23 @@ macro_rules! invoke_once {
}
}
pub struct OnDrop<F: FnOnce()>(Option<F>);
impl<F: FnOnce()> OnDrop<F> {
pub fn new(fun: F) -> Self {
Self(Some(fun))
}
}
impl<F: FnOnce()> Drop for OnDrop<F> {
fn drop(&mut self) {
if let Some(fun) = self.0.take() {
fun()
}
}
}