Currently move
takes ownership over all the variables in the environment of the closure. It would be nice to have finer grained control and be able to only move certain variables, perhaps with syntax like
move {x, y} |a, b| { ... }
(Whether or not you're already aware of this, other people reading may not be.)
It's always possible to take an explicit reference to the item you don't want to move, and use that:
let rx = &x;
let ry = &mut y;
move |a, b| { /* use rx and ry */ }
At one point it was even proposed that closures should _only_ be by-move, and the above should be done whenever one wants by-ref, but in the end the current split between non-move
and move
closures was added just for the sake of ergonomics.
To be fair, the manual way requires manual derferencing inside the closure body. The proposed system would actually allow more seamless mixing in that regard.
Yeah. Just to be clear that it's only a question of convenience and not expressiveness.
Most helpful comment
(Whether or not you're already aware of this, other people reading may not be.)
It's always possible to take an explicit reference to the item you don't want to move, and use that:
At one point it was even proposed that closures should _only_ be by-move, and the above should be done whenever one wants by-ref, but in the end the current split between non-
move
andmove
closures was added just for the sake of ergonomics.