In this chapter, weâll look at enumerations, also referred to as enums. Enums allow you to define a type by enumerating its possible variants. First weâll define and use an enum to show how an enum can encode meaning along with data. Next, weâll explore a particularly useful enum, called Option
, which expresses that a value can be either something or nothing. Then weâll look at how pattern matching in the match
expression makes it easy to run different code for different values of an enum. Finally, weâll cover how the if let
construct is another convenient and concise idiom available to handle enums in your code.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3