Skip to content

Commit b28debd

Browse files
committed
Rollup merge of rust-lang#31843 - Wafflespeanut:bool_docs, r=steveklabnik
fixes rust-lang#29332 r? @steveklabnik
2 parents ac02f9c + eb97c26 commit b28debd

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

src/libstd/primitive_docs.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,50 @@
1212
//
1313
/// The boolean type.
1414
///
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).
1559
mod prim_bool { }
1660

1761
#[doc(primitive = "char")]
@@ -533,4 +577,3 @@ mod prim_isize { }
533577
/// *[See also the `std::usize` module](usize/index.html).*
534578
///
535579
mod prim_usize { }
536-

0 commit comments

Comments
 (0)