pattern
Rust Combine alternatives with or-patterns
Use an or-pattern to share behavior across multiple alternatives. Alternatives that bind names must bind the same names with compatible types and binding modes. Expected output (not executed): weekend Why: The first literal alternative matches. Common mistake: The `|` in a pattern is not the Boolean OR expression `||`.
Formal Syntax & Structure
rust syntaxrust
pattern_a | pattern_bWorking Example
Example Snippetrust
fn main() { let day = "Sat"; let kind = match day { "Sat" | "Sun" => "weekend", _ => "weekday", }; println!("{kind}");}