Destructuring with let

To avoid using a tuple index, Rust has a way to destructure a tuple. This is very similar to a normal let statement, except we will define multiple variable names at once:

let (one, two, three) = (1, 2, 3); 

If there are the same number of names on the left as there are arguments on the right, Rust will break these up internally to create three bindings at once.

We now have three bindings and can access them as we would any other variable:

let (one, two, three) = (1, 2, 3); 
println!("One = {}", one); // outputs One = 1 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset