Re:Rust for C++ Programmers – Part 9
by kwantam on Thursday July 17, 2014 @07:18PM
(#8050795)
You can destructure without moving, as you suggest, by taking a reference.
Move:
let x = (box 2u, box 4u);
let (y, z) = match x {
(first, second) => (first, second)
};
println!("x is {}", x);
// this will not compile: x is moved into y and z
Reference:
let x = (box 2u, box 4u);
let (y, z) = match x {
(ref first, ref second) => (first, second)
};
println!("x is {}", x);
// this works fine
Move:
Reference: