The match Expression in Depth
The match Expression in Depth
match enables exhaustive pattern matching. Every possible case must be handled.
#[derive(Debug)]
enum Priority {
Low,
Medium,
High,
Critical(u8),
}
fn inspect_priority(p: Priority) {
match p {
Priority::Low => println!("Low priority - queue normally"),
Priority::Medium => println!("Medium priority - assign SLA"),
Priority::High => println!("High priority - alert on-call"),
Priority::Critical(level) => println!("CRITICAL (level {}) - page team immediately", level),
}
}
fn main() {
inspect_priority(Priority::High);
inspect_priority(Priority::Critical(1));
}