SQ in silver chrome letters, a lab's gear stacked against the S: a rack, two oscilloscopes, pizza boxes and a six-pack. Strange Query Lab
Chapters

rust-cardiac

  1. Contents
  2. Lexical structure
  3. Macros
  4. Items
  5. Attributes
  6. Statements and expressions
  7. Patterns
  8. Types
  9. Memory
  10. Panic
  11. Unsafety
  12. Constant evaluation
  13. The runtime
  14. Appendix: The core library

CARDIAC › rust-cardiac › Language Reference › Patterns

Patterns

What's different on CARDIAC

  • A match tests its arms one after another, so put the most common arm first.
  • Ranges are cheaper to test than equalities.
  • Otherwise patterns work as in Rust.

Where patterns work

Patterns work in match, if let, while let, let else and let. They can match integers, bools, chars, enums, structs, tuples and arrays, with ranges, guards, @ bindings, | alternatives and nested patterns.

Slice patterns work on arrays and slices: [first, .., last], [a, ..], [], and [x, rest @ ..].

A match tests its arms one after another, so the cost of an arm depends on its pattern. A range is tested with < and >=, which CARDIAC does directly, while an equality takes two tests: see Statements and expressions.

Refused by rustc: let Some(x) = o; is a refutable pattern in a plain let, which rustc refuses (E0005) and which builds nowhere. Use let else or if let.

Feature tests: patterns.