Skip to content

Impl Not operator trait for bool #7635

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

Closed
wants to merge 1 commit into from
Closed
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
25 changes: 25 additions & 0 deletions src/libstd/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ A quick summary:
Implementations of the following traits:

* `FromStr`
* `ToStr`
* `Not`
* `Ord`
* `TotalOrd`
* `Eq`
Expand All @@ -36,6 +38,8 @@ Finally, some inquries into the nature of truth: `is_true` and `is_false`.

#[cfg(not(test))]
use cmp::{Eq, Ord, TotalOrd, Ordering};
#[cfg(not(test))]
use ops::Not;
use option::{None, Option, Some};
use from_str::FromStr;
use to_str::ToStr;
Expand Down Expand Up @@ -254,6 +258,27 @@ pub fn all_values(blk: &fn(v: bool)) {
#[inline]
pub fn to_bit(v: bool) -> u8 { if v { 1u8 } else { 0u8 } }

/**
* The logical complement of a boolean value.
*
* # Examples
*
* ~~~rust
* rusti> !true
* false
* ~~~
*
* ~~~rust
* rusti> !false
* true
* ~~~
*/
#[cfg(not(test))]
impl Not<bool> for bool {
#[inline]
fn not(&self) -> bool { !*self }
}

#[cfg(not(test))]
impl Ord for bool {
#[inline]
Expand Down