match is Rust's most powerful control-flow tool. It compares a value against patterns and runs the first arm that fits — but its superpower is that the compiler forces you to cover every case.
Match is an expression
Like if, match produces a value, so you can assign its result. Each arm is pattern => expression. The patterns can bind the data inside a variant: Some(n) => ... pulls the inner value out as n, ready to use in that arm.
Exhaustiveness is the magic
A match must handle every possible case, or it won't compile. Match on an Option and forget None? Compile error. This sounds pedantic until you change an enum: add a variant, and the compiler instantly lists every match that no longer covers all cases. Refactoring becomes a guided checklist instead of a hunt for forgotten spots.
else or an unhandled enum value in other languages simply can't survive compilation here. Add a variant and the compiler hands you the to-do list.The wildcard, used with care
_ matches anything and is how you say 'all remaining cases.' It's useful, but it also opts you out of exhaustiveness checking for future variants — add a new variant and a _ arm silently swallows it. Use _ when you truly mean 'everything else'; spell out variants when you want the compiler to remind you later.