Structural patterns

Structural patterns mirror the value's shape. Tuple patterns name fixed slots. Array patterns may require fixed positions and capture a remainder with ..name.

whole @ pattern binds the complete matched value while also refining its inside. Nested patterns compose, provided every successful alternative binds the same names and types.

fn main() {
  let point = (0, 0)
  println(match point { (0, 0) => "origin", _ => "elsewhere" })
  let values = [1, 2, 3]
  match values {
    [head, ..tail] => println("head $head, tail $tail"),
    _ => println("empty"),
  }
}
Output & diagnostics
Expected:
origin
head 1, tail [2, 3]
Ctrl/⌘+Enter runs the current lesson.