タプル
以下のように、タプルはmatchを用いてデストラクトすることができます。
fn main() {
let triple = (0, -2, 3);
// TODO ^ `triple`に別の値を入れてみましょう。
println!("Tell me about {:?}", triple);
// `match`を用いてタプルをデストラクトしてみましょう。
match triple {
// 2つ目と3つ目の要素をデストラクト。
(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"),
(.., 2) => println!("last is `2` and the rest doesn't matter"),
(3, .., 4) => println!("First is `3`, last is `4`, and the rest doesn't matter"),
// `..`を使うと、タプルの残りの部分を無視できます。
_ => println!("It doesn't matter what they are"),
// ここでは`_`は、値を変数に束縛しないことを意味します。
}
}