- match
- case
match
- Similar to case or switch in other languages, match provides several arms.
examples/booleans/match-operator/src/main.rs
fn greet(text: &str) { match text { "morning" => println!("Good morning"), "night" => println!("Goodnight"), // "morning" => println!("Again"), warning: unreachable pattern "Jane" | "Joe" => println!("Hello {text}"), _ => println!("Hello World!"), } } fn main() { greet("morning"); greet("night"); greet("Jane"); greet("Joe"); greet("George"); }
Good morning Goodnight Hello Jane Hello Joe Hello World!