A macro for capturing variables on a per variable basis.
With this macro it is possible to specifically designate which variables will be captured by which method. Variables can be either specified to be moved, referenced, mutably referenced or cloned. Unspecified variables will automatically be moved.
The specifiers for each capture type are:
- move
- ref
- ref mut
- clone
This avoids having to manually declare references ahead of a move closure in order to prevent unwanted moves.
Examples
Spawning a Thread
Instead of having to write:
use thread;
use ;
You can now write:
extern crate closure;
use thread;
use ;
Mixing move and reference captures without having to specifically declare the references:
extern crate closure;
use *;
Variable identifiers in the argument position (between the vertical lines) can also be used same as in regular closures. Also, for the sake of completeness, the regular closure syntax can be used within the macro as well.
Limitations
Closure syntax specifying the argument and return types are currently not supported.