File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -77,3 +77,54 @@ mod let_keyword { }
7777///
7878/// [book]: https://doc.rust-lang.org/book/second-edition/ch05-01-defining-structs.html
7979mod struct_keyword { }
80+
81+ #[ doc( keyword = "enum" ) ]
82+ //
83+ /// The `enum` keyword.
84+ ///
85+ /// The `enum` keyword is used to define an enum type.
86+ ///
87+ /// Example:
88+ ///
89+ /// ```
90+ /// enum Foo {
91+ /// Value1,
92+ /// Value2,
93+ /// Value3(u32),
94+ /// Value4 { x: u32, y: u64 },
95+ /// }
96+ /// ```
97+ ///
98+ /// This is very convenient to handle different kind of data. To see which variant a value of an
99+ /// enum type is of, you can use pattern matching on the value:
100+ ///
101+ /// ```
102+ /// enum Foo {
103+ /// Value1,
104+ /// Value2,
105+ /// Value3(u32),
106+ /// Value4 { x: u32, y: u64 },
107+ /// }
108+ ///
109+ /// let x = Foo::Value1;
110+ ///
111+ /// match x {
112+ /// Foo::Value1 => println!("This is Value1"),
113+ /// Foo::Value2 => println!("This is Value2"),
114+ /// Foo::Value3(_) => println!("This is Value3"),
115+ /// Foo::Value4 { .. } => println!("This is Value4"),
116+ /// }
117+ ///
118+ /// // Or:
119+ ///
120+ /// if let Foo::Value1 = x {
121+ /// println!("This is Value1");
122+ /// } else {
123+ /// println!("This not Value1");
124+ /// }
125+ /// ```
126+ ///
127+ /// For more information, take a look at the [Rust Book][book].
128+ ///
129+ /// [book]: https://doc.rust-lang.org/book/second-edition/ch06-01-defining-an-enum.html
130+ mod enum_keyword { }
You can’t perform that action at this time.
0 commit comments