Rust TutorialLesson 13Free preview
Rust Match
This lesson is part of Rust · All levels
Summary
This lesson peels out the matching construction in Rust which is a very powerful pattern matching mechanism. Compared to 'switch' in other languages, 'match' in Rust checks for the fulfilment of all possible conditions (exhaustive checking). This pattern is often used in conjunction with enum and structured value testing.
Key points
- Match compares a value to a set of patterns (arms)
- Patterns and expressions are connected using the thick arrow symbol '=>'
- Rust compiler requires a match pattern to be exhaustive (including all possibilities)
- The lower-line placeholder character '_' serves as the default (catch-all) pattern
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.