Pattern matching
match expression
match scrutinee '{' pattern '=>' result ( ',' pattern '=>' result )* ','? '}'
An optional if guard may appear after a pattern and before => where supported.
Pattern forms
| Pattern | Example / note |
|---|---|
| Wildcard | _ matches anything |
| Binding | bare name binds the value |
| Literal | numbers, strings, booleans |
| Tuple | ( p1, p2, … ) |
| Struct-like | fields with sub-patterns |
| Enum variant | qualified name with optional inner pattern |
| Alternatives | p1 | p2 |
Trailing commas after the last arm are allowed.
Result expression
Each arm’s result is a full expression: blocks, calls, nested match, casts, etc.
See also Expressions.