tuples

Tuples can be destructured in a match as follows:

  1. fn main() {
  2. let pair = (0, -2);
  3. // TODO ^ Try different values for `pair`
  4. println!("Tell me about {:?}", pair);
  5. // Match can be used to destructure a tuple
  6. match pair {
  7. // Destructure the second
  8. (0, y) => println!("First is `0` and `y` is `{:?}`", y),
  9. (x, 0) => println!("`x` is `{:?}` and last is `0`", x),
  10. _ => println!("It doesn't matter what they are"),
  11. // `_` means don't bind the value to a variable
  12. }
  13. }

See also:

Tuples