drop-guard.rs/src/impl_arbitrary.rs

19 lines
383 B
Rust

use crate::DropGuarded;
pub struct ArbitraryDropGuard<F: FnOnce() -> ()>(Option<F>);
impl<F: FnOnce() -> ()> ArbitraryDropGuard<F> {
#[inline]
pub const fn new(f: F) -> Self {
Self(Some(f))
}
}
impl<F: FnOnce() -> ()> DropGuarded for ArbitraryDropGuard<F> {
fn cancel(mut self) {
if let Some(f) = self.0.take() {
f();
}
}
}