#clone #variables #list #calling #expression #block #macro

clone-block

A very simple macro that clones a list of variables before calling an expression

Show the crate…

2 releases

0.1.1 Aug 30, 2020
0.1.0 Aug 30, 2020

#44 in #calling

23 downloads per month

MPL-2.0 license

8KB

A very simple macro that clones a list of variables before calling an expression

img img img

Based on this tweet: https://twitter.com/untitaker/status/1299812136202493953

use clone_block::clone;
use std::thread;

let foo = "foo".to_string();

let thread = thread::spawn(
    clone!(foo; move || {
        let foobar = format!("{}bar", foo);
        foobar
    })
);

let foobar = thread.join();
let foobaz = format!("{}baz", foo);

License

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.


lib.rs:

A very simple macro that clones a list of variables before calling an expression.

Based on this tweet: https://twitter.com/untitaker/status/1299812136202493953

Example

use clone_block::clone;
use std::thread;

let foo = "foo".to_string();

let thread = thread::spawn(
    clone!(foo; move || {
        let foobar = format!("{}bar", foo);
        foobar
    })
);

let foobar = thread.join();
let foobaz = format!("{}baz", foo);

No runtime deps