This is a fork of the closure crate by Oliver Giersch which is no longer maintained.
This crate provides a macro which lets you write closures that can capture variables individually, either by moving, referencing, or transforming by a method.
Start by adding an entry to your Cargo.toml
:
[dependencies]
closure = "0.3.0"
Then you can write closures like so:
use closure::closure;
let string = "move".to_string();
let x = 10;
let mut y = 20;
let rc = Rc::new(5);
let closure = closure!([move string, ref x, ref mut y, clone rc] move |arg: i32| {
...
});