diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2016-02-25 04:21:10 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2016-02-25 04:21:10 +0530 |
| commit | b28debd91ca23afcc9485f16690de052bd181e58 (patch) | |
| tree | b30d35b2b4137bc18c33e03f24245358a60da5b0 /src/libstd | |
| parent | ac02f9c18d601bec9740c552d0ba554ae62bd60c (diff) | |
| parent | eb97c26d3b3a3c59ddd48fba2780259b906904a1 (diff) | |
| download | rust-b28debd91ca23afcc9485f16690de052bd181e58.tar.gz rust-b28debd91ca23afcc9485f16690de052bd181e58.zip | |
Rollup merge of #31843 - Wafflespeanut:bool_docs, r=steveklabnik
fixes #29332 r? @steveklabnik
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/primitive_docs.rs | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/libstd/primitive_docs.rs b/src/libstd/primitive_docs.rs index b840e51873e..e5819522123 100644 --- a/src/libstd/primitive_docs.rs +++ b/src/libstd/primitive_docs.rs @@ -12,6 +12,50 @@ // /// The boolean type. /// +/// The `bool` represents a value, which could only be either `true` or `false`. +/// +/// # Basic usage +/// +/// `bool` implements various traits, such as [`BitAnd`], [`BitOr`], [`Not`], etc., +/// which allow us to perform boolean operations using `&`, `|` and `!`. +/// +/// [`if`] always demands a `bool` value. [`assert!`], being an important macro in testing, +/// checks whether an expression returns `true`. +/// +/// ``` +/// let bool_val = true & false | false; +/// assert!(!bool_val); +/// ``` +/// +/// [`assert!`]: std/macro.assert!.html +/// [`if` conditionals]: ../../book/if.html +/// [`BitAnd`]: ../ops/trait.BitAnd.html +/// [`BitOr`]: ../ops/trait.BitOr.html +/// [`Not`]: ../ops/trait.Not.html +/// +/// # Examples +/// +/// A trivial example of the usage of `bool`, +/// +/// ``` +/// let praise_the_borrow_checker = true; +/// +/// // using the `if` conditional +/// if praise_the_borrow_checker { +/// println!("oh, yeah!"); +/// } else { +/// println!("what?!!"); +/// } +/// +/// // ... or, a match pattern +/// match praise_the_borrow_checker { +/// true => println!("keep praising!"), +/// false => println!("you should praise!"), +/// } +/// ``` +/// +/// Also, since `bool` implements the [`Copy`](../marker/trait.Copy.html) trait, we don't +/// have to worry about the move semantics (just like the integer and float primitives). mod prim_bool { } #[doc(primitive = "char")] @@ -533,4 +577,3 @@ mod prim_isize { } /// *[See also the `std::usize` module](usize/index.html).* /// mod prim_usize { } - |
