Pattern matching
match form
match value: Pattern1 -> expr1 Pattern2 -> expr2 _ -> defaultmatch is exhaustive — the compiler refuses to emit if a sum-type
match doesn’t cover every variant or have a wildcard.
Patterns
# literalmatch n: 0 -> "zero" 1 -> "one" _ -> "many"
# structmatch decision: Decision { refund: true, amount, ... } -> "refund " + amount.to_string() Decision { refund: false, reason } -> "denied: " + reason
# sum typematch status: Pending -> "waiting" Approved(who) -> "by " + who Denied(reason) -> reason
# Option / Result (just sum types underneath)match find(xs, n): Some(x) -> "got " + x.to_string() None -> "no match"
# binding the matched valuematch status: s @ Approved(_) -> log(s) other -> log(other)
# guardmatch x: n if n > 100 -> "big" n if n > 10 -> "medium" _ -> "small"Destructuring in let and parameters
let Decision { refund, amount, .. } = compute_decision(ticket)
fn handle(Decision { refund, amount, reason }: Decision) -> String: ...Exhaustiveness
match status: Pending -> "waiting" Approved(who) -> "by " + who # error: missing variant `Denied`Add the missing arm or a _ -> ... catch-all.