匹配块可在各种方式析构项目中。
元组
元组可以在匹配中被析构如下:
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 } }
也可以看看:
元组