Greetings,

Today Rust has a new closure syntax:

    let two_three_four = [1, 2, 3].map( |i| i + 1 );

That's it - `|args| expression`. You are going to want to sprinkle them 
everywhere because they are irresistible.

Capture clauses still go alongside the arguments. Usually these aren't 
required, but occasionally one needs an explicit copy or move if copying would 
be expensive:

    let x = cat, y = dog, z = turnip;
    let party = |w, move x, copy y| w + x + y + z;

Argument and return type annotations are optional.

    let party = |x: Cat, y: Dog| -> Octopus x + y;

When your lambdas get bigger you can put the body in a block:

    spawn( || {
        let x = foo();
        loop {
             etc();
        }
    });

The new `do` syntax lets you write higher order functions more like 
language-level control structures by moving the closure outside of the argument 
list. This replaces the previous syntax for making sugared block calls.

    do unpack_slice(rhs) |p, len| {
        for range(0, len) |i| {
            ...
        }
    }

Empty argument lists can be omitted in both `for` and `do`

    do spawn {
        ...
    }

Yep!

-Brian
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to