Loading RustViz Engine...
Implement custom RAII guard that executes cleanup logic upon dropping.
This problem is currently in blueprint template mode. Once the concept foundation is finalized, live in-browser WebAssembly compilation and test assertion runners will be enabled here.
pub struct ScopeGuard<F: FnOnce()> {
cleanup: Option<F>,
}
impl<F: FnOnce()> ScopeGuard<F> {
pub fn new(f: F) -> Self { Self { cleanup: Some(f) } }
pub fn defuse(&mut self) { self.cleanup = None; }
}
impl<F: FnOnce()> Drop for ScopeGuard<F> {
fn drop(&mut self) {
if let Some(f) = self.cleanup.take() {
f();
}
}
}