Right now you can destructure with a pattern everywhere where you can introduce new local variables: let
, match
and in function signatures.
However, sometimes you are in the need of destructuring some values, but don't want to introduce a new variable for them, instead intending to store their result in some mutable bindings that are already in scope. To achieve that right now, you have to create a temporary local variable and move its content to the other one. Example:
fn foo() -> (int, int, int);
let mut x = 42;
let mut z = 0;
loop {
let (x_, _, z_) = foo();
x = x_;
y = y_;
// ...
}
// Do something with x, y ...
If we gain the in
keyword, it could be used for a new assignment statement that works similar to let
, but doesn't introduce new variables:
fn foo() -> (int, int, int);
let mut x = 42;
let mut z = 0;
loop {
in (x, _, z) = foo();
// ...
}
// Do something with x, y ...
@jensnockert: See reply here http://www.reddit.com/r/rust/comments/1hsqf5/proposal_for_an_additional_use_case_of_the_in/caxkxjd