capture.rs

Travis-CI Status

A macro for adding explicit capture clauses to a (closure-) expression.

Using this macro, it becomes possible to be explicit about what variables a closure captures, and by which capture mode it does so.

Syntax

ignore capture!($([move IDENT,] [ref IDENT,] [IDENT IDENT,])* in EXPR)

Semantic

The macro will expand to nested block expressions with a let binding per capture clause:

These bindings will be in scope for the final EXPR expression, which will usually be a by-value capturing closure.

Current limitations and future changes

Example

Using the macro:

```rust

![feature(phase)]

![feature(unboxed_closures)]

[phase(plugin)]

extern crate capture;

fn main() { let (x, y, z) = (1u32, 2u32, 3u32); let g = capture!(move x, ref y, clone z in move |:| x + *y + z);

assert_eq!(g(), 6);

} ```

```