21.11 OR Patterns and Combined Guards
Use the |
operator to combine multiple patterns in one arm:
#![allow(unused)] fn main() { fn check_char(c: char) { match c { 'a' | 'A' => println!("Found an 'a'!"), _ => println!("Not an 'a'"), } } }
You can also mix guards and OR patterns. For example:
fn main() { let x = 4; let b = false; match x { // Matches if x is 4, 5, or 6, AND b == true 4 | 5 | 6 if b => println!("yes"), _ => println!("no"), } }