Macro clone_all::clone_all [] [src]

macro_rules! clone_all {
    ($($i:ident),+) => { ... };
}

Clones all the given variables into new variables. Intended for use with move closures.

Examples

Compare this:

 
let i = Arc::new(Mutex::new(String::from("hello world")));
let o = Arc::new(Mutex::new(String::new()));
for _ in "hello world".chars() {
    thread::spawn({let i = i.clone(); let o = o.clone(); move || {
        let c = i.lock().unwrap().pop();
        let c = c.unwrap();
        o.lock().unwrap().push(c);
    }}).join();
}

To this:

#[macro_use]
extern crate clone_all;
 
let i = Arc::new(Mutex::new(String::from("hello world")));
let o = Arc::new(Mutex::new(String::new()));
for _ in "hello world".chars() {
    thread::spawn({clone_all!(i, o); move || {
        let c = i.lock().unwrap().pop();
        let c = c.unwrap();
        o.lock().unwrap().push(c);
    }}).join();
}