#closures #proc-macro #variables #kind #specifying #arguments #capture

macro closure-pass

Proc-macro for specifying kind of passing variables to closures

1 unstable release

0.1.0 May 3, 2020

#10 in #specifying

Download history 9/week @ 2024-03-30 4/week @ 2024-04-06

69 downloads per month

MIT/Apache

7KB
78 lines

closure-pass is a crate for passing arguments to a closure with capture feature of C++ lambdas.

Usage

So far, this crate requires two nightly features: stmt_expr_attributes and proc_macro_hygiene. Usage is pretty straightforward, the following code:

let a = /*..*/;
let b = /*..*/;

#[closure_pass(a, b = b.f()]
move || {
    // ..
}

Will expand to something like:

let a = /*..*/;
let b = /*..*/;

{
    let a = a.clone();
    let b = b.f();
    move || {
        // ..
    }
}

Dependencies

~1.5MB
~36K SLoC