20 lines
956 B
HTML
20 lines
956 B
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<title>Enums and Pattern Matching</title>
|
||
</head>
|
||
<body>
|
||
<h1 id="enums-and-pattern-matching"><a class="header" href="#enums-and-pattern-matching">Enums and Pattern Matching</a></h1>
|
||
<p>In this chapter, we’ll look at enumerations, also referred to as <em>enums</em>.
|
||
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 <code>Option</code>, which
|
||
expresses that a value can be either something or nothing. Then, we’ll look at
|
||
how pattern matching in the <code>match</code> expression makes it easy to run different
|
||
code for different values of an enum. Finally, we’ll cover how the <code>if let</code>
|
||
construct is another convenient and concise idiom available to handle enums in
|
||
your code.</p>
|
||
</body>
|
||
</html>
|