#guard #boilerplate #write #less #allowing #arc #arc-mutex-t

arc-guard

Guard around Arc<Mutex<T>> allowing you to write less boilerplate code

2 unstable releases

0.2.0 Mar 6, 2019
0.1.0 Mar 3, 2019

#17 in #allowing

45 downloads per month

MIT license

6KB

ArcGuard

Guard around Arc<Mutex<T>> allowing you to write less boilerplate code.

Full Documentation can be read here.

Example

Before:

use std::sync::{Arc, Mutex};

let indicator = Arc::new(Mutex::new(Indicator::new()));
let indicator_clone = indicator.clone();
let indicator_clone = indicator_clone.lock().expect("Unable to lock indicator.");

indicator_clone.do_something();

drop(indicator_clone);

After:

use arc_guard::ArcGuard;

let indicator = ArcGuard::new(Indicator::new());

indicator.execute(|indicator| {
    let indicator = indicator.lock().expect("Unable to lock indicator.");
    indicator.do_something();
});

lib.rs:

ArcGuard

A Guard around Arc<Mutex<T>> allowing you to write less boilerplate code.

Example

Before:

use std::sync::{Arc, Mutex};

let indicator = Arc::new(Mutex::new(Indicator::new()));
let indicator_clone = indicator.clone();
let indicator_clone = indicator_clone.lock().expect("Unable to lock indicator.");

indicator_clone.do_something();

drop(indicator_clone);

After:

use arc_guard::ArcGuard;

let indicator = ArcGuard::new(Indicator::new());

indicator.execute(|indicator| {
    let indicator = indicator.lock().expect("Unable to lock indicator.");
    indicator.do_something();
});

No runtime deps