元组

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

1. fn main() {
2. let pair = (0, -2);
3. // 试一试 ^ 将不同的值赋给 `pair`

5. println!("Tell me about {:?}", pair);
6. // match 可以解构一个元组
7. match pair {
8. // 绑定到第二个元素
9. (0, y) => println!("First is `0` and `y` is `{:?}`", y),
10. (x, 0) => println!("`x` is `{:?}` and last is `0`", x),
11. _      => println!("It doesn't matter what they are"),
12. // `_` 表示不将值绑定到变量
13. }
14. }

参见:

元组