|
12 | 12 | //
|
13 | 13 | /// The boolean type.
|
14 | 14 | ///
|
| 15 | +/// The `bool` represents a value, which could only be either `true` or `false`. |
| 16 | +/// |
| 17 | +/// # Basic usage |
| 18 | +/// |
| 19 | +/// `bool` implements various traits, such as [`BitAnd`], [`BitOr`], [`Not`], etc., |
| 20 | +/// which allow us to perform boolean operations using `&`, `|` and `!`. |
| 21 | +/// |
| 22 | +/// [`if`] always demands a `bool` value. [`assert!`], being an important macro in testing, |
| 23 | +/// checks whether an expression returns `true`. |
| 24 | +/// |
| 25 | +/// ``` |
| 26 | +/// let bool_val = true & false | false; |
| 27 | +/// assert!(!bool_val); |
| 28 | +/// ``` |
| 29 | +/// |
| 30 | +/// [`assert!`]: std/macro.assert!.html |
| 31 | +/// [`if` conditionals]: ../../book/if.html |
| 32 | +/// [`BitAnd`]: ../ops/trait.BitAnd.html |
| 33 | +/// [`BitOr`]: ../ops/trait.BitOr.html |
| 34 | +/// [`Not`]: ../ops/trait.Not.html |
| 35 | +/// |
| 36 | +/// # Examples |
| 37 | +/// |
| 38 | +/// A trivial example of the usage of `bool`, |
| 39 | +/// |
| 40 | +/// ``` |
| 41 | +/// let praise_the_borrow_checker = true; |
| 42 | +/// |
| 43 | +/// // using the `if` conditional |
| 44 | +/// if praise_the_borrow_checker { |
| 45 | +/// println!("oh, yeah!"); |
| 46 | +/// } else { |
| 47 | +/// println!("what?!!"); |
| 48 | +/// } |
| 49 | +/// |
| 50 | +/// // ... or, a match pattern |
| 51 | +/// match praise_the_borrow_checker { |
| 52 | +/// true => println!("keep praising!"), |
| 53 | +/// false => println!("you should praise!"), |
| 54 | +/// } |
| 55 | +/// ``` |
| 56 | +/// |
| 57 | +/// Also, since `bool` implements the [`Copy`](../marker/trait.Copy.html) trait, we don't |
| 58 | +/// have to worry about the move semantics (just like the integer and float primitives). |
15 | 59 | mod prim_bool { }
|
16 | 60 |
|
17 | 61 | #[doc(primitive = "char")]
|
@@ -533,4 +577,3 @@ mod prim_isize { }
|
533 | 577 | /// *[See also the `std::usize` module](usize/index.html).*
|
534 | 578 | ///
|
535 | 579 | mod prim_usize { }
|
536 |
| - |
|
0 commit comments