元组

元组可以在 match 中解构,如下所示:

  1. fn main() {
  2. let triple = (0, -2, 3);
  3. // 试一试 ^ 将不同的值赋给 `triple`
  4. println!("Tell me about {:?}", triple);
  5. // match 可以解构一个元组
  6. match triple {
  7. // 解构出第二个和第三个元素
  8. (0, y, z) => println!("First is `0`, `y` is {:?}, and `z` is {:?}", y, z),
  9. (1, ..) => println!("First is `1` and the rest doesn't matter"),
  10. // `..` 可用来忽略元组的其余部分
  11. _ => println!("It doesn't matter what they are"),
  12. // `_` 表示不将值绑定到变量
  13. }
  14. }

参见:

元组