Crate with_api

Source
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§

bor_with
Borrows the value defined in the with_expr and evaluates the enclosing block
mut_with
Exclusively borrows the value defined in the with_expr and evaluates the enclosing block
with
Owns the value defined in the with_expr and evaluates the enclosing block