Conceptual
Login

Enums and Pattern Matching in Rust

An enum is a type whose value is exactly one of a listed set of possibilities, and each possibility can carry its own data. Pattern matching pulls that data back out while forcing you to say what happens in every case. Together they turn "did I remember to handle that state?" from a hope into a compiler error.

Questions this Concept answers

  • Why does the compiler's exhaustiveness check on `match` matter when you model a device's states as an enum?