@@ -124,6 +124,61 @@ mod const_keyword { }
124
124
/// [`pub`]: keyword.pub.html
125
125
mod crate_keyword { }
126
126
127
+ #[ doc( keyword = "enum" ) ]
128
+ //
129
+ /// For defining enumerations.
130
+ ///
131
+ /// Enums in Rust are similar to those of other compiled languages like C, but have important
132
+ /// differences that make them considerably more powerful. What Rust calls enums are more commonly
133
+ /// known as Algebraic Data Types if you're coming from a functional programming background, but
134
+ /// the important part is that data can go with the enum variants.
135
+ ///
136
+ /// ```rust
137
+ /// # struct Coord;
138
+ /// enum SimpleEnum {
139
+ /// FirstVariant,
140
+ /// SecondVariant,
141
+ /// ThirdVariant,
142
+ /// }
143
+ ///
144
+ /// enum Location {
145
+ /// Unknown,
146
+ /// Anonymous,
147
+ /// Known(Coord),
148
+ /// }
149
+ ///
150
+ /// enum ComplexEnum {
151
+ /// Nothing,
152
+ /// Something(u32),
153
+ /// LotsOfThings {
154
+ /// usual_struct_stuff: bool,
155
+ /// blah: String,
156
+ /// }
157
+ /// }
158
+ ///
159
+ /// enum EmptyEnum { }
160
+ /// ```
161
+ ///
162
+ /// The first enum shown is the usual kind of enum you'd find in a C-style language. The second
163
+ /// shows off a hypothetical example of something storing location data, with Coord being any other
164
+ /// type that's needed, for example a struct. The third example demonstrates the kind of variant a
165
+ /// variant can store, ranging from nothing, to a tuple, to an anonymous struct.
166
+ ///
167
+ /// Instantiating enum variants involves explicitly using the enum's name as its namespace,
168
+ /// followed by one of its variants. `SimpleEnum::SecondVariant` would be an example from above.
169
+ /// When data follows along with a variant, such as with rust's built-in [`Option`] type, the data
170
+ /// is added as the type describes, for example `Option::Some(123)`. The same follows with
171
+ /// struct-like variants, with things looking like `ComplexEnum::LotsOfThings { usual_struct_stuff:
172
+ /// true, blah: "hello!".to_string(), }`. Empty Enums are similar to () in that they cannot be
173
+ /// instantiated at all, and are used mainly to mess with the type system in interesting ways.
174
+ ///
175
+ /// For more information, take a look at the [Rust Book] or the [Reference]
176
+ ///
177
+ /// [`Option`]: option/enum.Option.html
178
+ /// [Rust Book]: https://doc.rust-lang.org/book/second-edition/ch06-01-defining-an-enum.html
179
+ /// [Reference]: https://doc.rust-lang.org/reference/items/enumerations.html
180
+ mod enum_keyword { }
181
+
127
182
#[ doc( keyword = "fn" ) ]
128
183
//
129
184
/// The `fn` keyword.
0 commit comments