Categorizing with Enumerations

The bouncer would like even more functionality. They’d like to know how to treat different visitors and if they can drink alcohol. The final set of improvements to the visitor list are:

  • Store an action associated with a visitor: admit them, admit them with a note, refuse entry, or mark them as probationary treehouse members.

  • Store the visitor’s age, and forbid them from drinking if they’re under 21.

Enumerations

Rust lets you define a type that can only be equal to one of a set of predefined values. These are known as enumerations, and are declared with the enum keyword. You are going to define an enumeration listing each of the four actions associated with a visitor. Rust enumerations are very powerful, and can ...

Get Hands-on Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.