Patterns & destructuring
A pattern is what a match arm accepts. It is not the match statement
itself — that lives with statements — it is the shape
on the left of each case: a literal, a type, a binding, or a
destructured object or array.
and joins patterns that must all hold; or offers alternatives.
let / mut / as bind a name to what matched. rest keeps the
leftover fields or elements. The same atoms appear when a union-typed
value is read back out by member type.
main {
let i32 ∪ string signum ← 7
match signum {
case i32 let n { print "a number" }
case string let s { print "a text" }
}
}Return to the grammar overview.
Terms#
These are the words you write in this part of the language. Each links to its page. The second column names the grammar rule the word belongs to.
| Term | Grammar rule |
|---|---|
and | patterns |
or | pattern |
let, as, mut | ut_pattern |
as | pattern_binding |
rest, as | pattern_property |
rest | array_pattern_element |
Formal grammar#
The rules for this part of the language are the parser's own definition of it. They are written for models and tools, so this page does not repeat them; the full list is at every production.