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