diff --git a/library/core/src/bool.rs b/library/core/src/bool.rs index 00164c631b305..01f53b3138a28 100644 --- a/library/core/src/bool.rs +++ b/library/core/src/bool.rs @@ -31,4 +31,23 @@ impl bool { pub fn then T>(self, f: F) -> Option { if self { Some(f()) } else { None } } + + /// Returns the opposite value. + /// + /// This is identical in functionality to usage of the `!` operator, it's + /// simply an alternate way to write it. Because it's post-fix instead of + /// pre-fix, it is often more readable within chained function call + /// expressions. + /// + /// # Examples + /// + /// ``` + /// assert_eq!(!true, true.not()); + /// assert_eq!(!false, false.not()); + /// ``` + #[unstable(feature = "bool_not_method", issue = "none")] + #[inline] + pub const fn not(self) -> Self { + !self + } }