How to Match on Multiple Patterns with | in Rust

Use the pipe operator | in a match arm to group multiple patterns that share the same execution logic.

Use the pipe operator | within a single match arm to handle multiple patterns with the same logic. This syntax allows you to group distinct values or patterns that should trigger the same code block without repeating the body.

fn main() {
    let number = 7;

    match number {
        1 | 3 | 5 | 7 => println!("Odd number: {}", number),
        2 | 4 | 6 | 8 => println!("Even number: {}", number),
        _ => println!("Other number"),
    }
}