Crate with_api[][src]

Expand description

With_api

A simple set of macros for the ergonomic shinking of scope.

Examples

use with_api::mut_with;

let protec: Mutex<HashMap<usize, String>> =
    Mutex::new(Vec::new().into_iter().collect());

// critical section minimised.
mut_with!(protec.lock().unwrap(), |db| {
    let _ = db.insert(42, "meaning of life".to_string());
    assert!(!db.is_empty());
});

Macros

Borrows the value defined in the with_expr and evaluates the enclosing block

Exclusively borrows the value defined in the with_expr and evaluates the enclosing block

Owns the value defined in the with_expr and evaluates the enclosing block