Crate mini_scopeguard

Crate mini_scopeguard 

Source
Expand description

A minimal scopeguard implementation

§Examples

{
    // Create a new guard around a string that will
    // print its value when dropped.
    let s = String::from("Chashu likes tuna");
    let mut s = Guard::new(s, |s| println!("{s}"));
     
    // Modify the string contained in the guard.
    s.push_str("!!!");
     
    // The guard will be dropped here.
}

§Comparison to scopeguard

The scopeguard crate provides several settings to configure when exactly the closure should run. This seems like a fairly niche capability, and so this crate removes those. The implementation of this crate borrows key parts from scopeguard, and credit goes out to its authors for figuring out the hard parts.

Structs§

Guard
Wrap a value and run a closure when dropped.