Rust匹配析構元組

匹配塊可在各種方式析構項目中。

元組

元組可以在匹配中被析構如下:

fn main() {
let pair = (0, -2);
// TODO ^ Try different values for `pair`

println!("Tell me about {:?}", pair);
// Match can be used to destructure a tuple
match pair {
    // Destructure the second
    (0, y) => println!("First is \`0\` and \`y\` is \`{:?}\`", y),
    (x, 0) => println!("\`x\` is \`{:?}\` and last is \`0\`", x),
    \_      => println!("It doesn't matter what they are"),
    // \`\_\` means don't bind the value to a variable
}

}

也可以看看:

元組