ondrop
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user