Skip to content

Commit

Permalink
Add enum keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Sep 4, 2018
1 parent 7219130 commit 0a23c42
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/libstd/keyword_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,54 @@ mod let_keyword { }
///
/// [book]: https://doc.rust-lang.org/book/second-edition/ch05-01-defining-structs.html
mod struct_keyword { }

#[doc(keyword = "enum")]
//
/// The `enum` keyword.
///
/// The `enum` keyword is used to define an enum type.
///
/// Example:
///
/// ```
/// enum Foo {
/// Value1,
/// Value2,
/// Value3(u32),
/// Value4 { x: u32, y: u64 },
/// }
/// ```
///
/// This is very convenient to handle different kind of data. To see which variant a value of an
/// enum type is of, you can use pattern matching on the value:
///
/// ```
/// enum Foo {
/// Value1,
/// Value2,
/// Value3(u32),
/// Value4 { x: u32, y: u64 },
/// }
///
/// let x = Foo::Value1;
///
/// match x {
/// Foo::Value1 => println!("This is Value1"),
/// Foo::Value2 => println!("This is Value2"),
/// Foo::Value3(_) => println!("This is Value3"),
/// Foo::Value4 { .. } => println!("This is Value4"),
/// }
///
/// // Or:
///
/// if let Foo::Value1 = x {
/// println!("This is Value1");
/// } else {
/// println!("This not Value1");
/// }
/// ```
///
/// For more information, take a look at the [Rust Book][book].
///
/// [book]: https://doc.rust-lang.org/book/second-edition/ch06-01-defining-an-enum.html
mod enum_keyword { }

0 comments on commit 0a23c42

Please sign in to comment.