Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the primitive docs for bool #31843

Merged
merged 1 commit into from
Feb 25, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion src/libstd/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to have a "Basic usage:" example which just shows assigning true or false, and comparing them. I dunno. It's tough. Thoughts? I'm on the fence.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, the example with match and if seemed to cover the basic usage, no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then maybe they should be moved above the assert! example, and given the "Basic usage:" tagline that I've been using as a convention (which admittedly, I should have mentioned and didn't say anything till now :( )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ie, you want the basic usage first, not second, even though the example is a bit more complex than a simple assert!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I've updated the thing - see if that's okay :)

/// 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")]
Expand Down Expand Up @@ -533,4 +577,3 @@ mod prim_isize { }
/// *[See also the `std::usize` module](usize/index.html).*
///
mod prim_usize { }