The match expression is exhaustive—it must cover all enum variants. if let handles a single pattern concisely.
match
match value { Some(x) => x, None => 0 }
Important interview questions and answers
- Q: Why exhaustive matching?
A: Compiler ensures you handle every case—no forgotten enum variant at runtime.
Self-check
- What happens if a
matchmisses a variant?
if let and while let
if let Some(x) = opt avoids verbose match when only one pattern matters. while let drains queues and optional streams idiomatically.
Guards
match arms can use if guards for extra conditions without nesting another match.