Skip to content
Closed
Changes from 3 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
13 changes: 13 additions & 0 deletions library/core/src/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,17 @@ impl bool {
pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
if self { Some(f()) } else { None }
}

/// Returns the opposite value.
///
/// # Examples
///
/// ```
/// assert_eq!(false.not(), true);
/// assert_eq!(true.not(), false);
/// ```
#[unstable(feature = "bool_not_method", issue = "none")]
pub fn not(self) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

This method could be a const fn, did you decide not to make it one to keep it identical to the Not::not method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point actually. i only thought of it initially as a replacement for the Not trait being in the prelude, but we could probably go const here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Tangentially, it being constable already can also be an added argument for making it an inherent method

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that the intention is to make it possible to make trait impls const also, but we're pretty far from seeing that stabilized.

!self
}
}