11% Enums
22
3- An ` enum ` in Rust is a type that represents data that could be one of
4- several possible variants:
3+ An ` enum ` in Rust is a type that represents data that is one of
4+ several possible variants. Each variant in the ` enum ` can optionally
5+ have data associated with it:
56
67``` rust
78enum Message {
@@ -12,9 +13,8 @@ enum Message {
1213}
1314```
1415
15- Each variant can optionally have data associated with it. The syntax for
16- defining variants resembles the syntaxes used to define structs: you can
17- have variants with no data (like unit-like structs), variants with named
16+ The syntax for defining variants resembles the syntaxes used to define structs:
17+ you can have variants with no data (like unit-like structs), variants with named
1818data, and variants with unnamed data (like tuple structs). Unlike
1919separate struct definitions, however, an ` enum ` is a single type. A
2020value of the enum can match any of the variants. For this reason, an
@@ -41,7 +41,7 @@ let y: BoardGameTurn = BoardGameTurn::Move { squares: 1 };
4141Both variants are named ` Move ` , but since they’re scoped to the name of
4242the enum, they can both be used without conflict.
4343
44- A value of an enum type contains information about which variant it is,
44+ A value of an ` enum ` type contains information about which variant it is,
4545in addition to any data associated with that variant. This is sometimes
4646referred to as a ‘tagged union’, since the data includes a ‘tag’
4747indicating what type it is. The compiler uses this information to
@@ -67,7 +67,7 @@ equality yet, but we’ll find out in the [`traits`][traits] section.
6767
6868# Constructors as functions
6969
70- An enum’s constructors can also be used like functions . For example:
70+ An ` enum ` constructor can also be used like a function . For example:
7171
7272``` rust
7373# enum Message {
@@ -76,7 +76,7 @@ An enum’s constructors can also be used like functions. For example:
7676let m = Message :: Write (" Hello, world" . to_string ());
7777```
7878
79- Is the same as
79+ is the same as
8080
8181``` rust
8282# enum Message {
0 commit comments