- _
- underscore
Destructuring tuple
- It is not destructing! Just looks similar.
- It means taking the values of a tuple apart into individual variables.
- We have to assign all the values.
- We can use the underscore _ (multiple times) as a placeholder for the value we don't want to assign.
- Alternatively, we could assign them one-by-one.
examples/tuples/destructuring-tuple/src/main.rs
fn main() { let things = (11, '2', String::from("three"), 19, 23); let (a, _, c, _, e) = &things; // Destructuring the tuple println!("{a}"); println!("{c}"); println!("{e}"); println!(); let (x, y) = (&things.2, &things.4); println!("{x}"); println!("{y}"); }
11 three 23 three 23