pub struct Guard<F: FnOnce()> {
action: Option<F>,
}
impl<F: FnOnce()> Guard<F> {
pub fn new(action: F) -> Self {
Self { action: Some(action) }
}
pub fn commit(self) {}
pub fn dismiss(mut self) {
let _ = self.action.take();
}
}
impl<F: FnOnce()> Drop for Guard<F> {
fn drop(&mut self) {
if let Some(action) = self.action.take() {
action()
}
}
}