通过例子学习Rust

16.1 解构和解构条件

The arms of a match block can be destructured, and a guard can be added to further filter the arm.

fn main() { let pair = (2i, -2); // TODO ^ Try different values for `pair` println!("Tell me about {}", pair); // Match can be used to destructure a tuple match pair { // Destructure the tuple (x, y) if x == y => println!("These are twins"), // The ^ `if condition` part is a guard (x, y) if x + y == 0 => println!("Antimatter, kaboom!"), // `_` means don't bind the value to a variable (x, _) if x % 2 == 1 => println!("The first one is odd"), _ => println!("No correlation..."), } }