pub struct ScopeGuard<F: FnMut()> {
f: F,
}
pub fn scope_guard<F: FnMut()>(f: F) -> ScopeGuard<F> {
ScopeGuard::<F> { f }
}
impl<F: FnMut()> ScopeGuard<F> {
pub fn release(self) {
std::mem::forget(self);
}
}
impl<F: FnMut()> Drop for ScopeGuard<F> {
fn drop(&mut self) {
(self.f)()
}
}