@@ -23,6 +23,9 @@ pub trait BoolExt {
|
|||||||
#[allow(clippy::result_unit_err)]
|
#[allow(clippy::result_unit_err)]
|
||||||
fn into_result(self) -> Result<(), ()>;
|
fn into_result(self) -> Result<(), ()>;
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
fn is_false(&self) -> Self;
|
||||||
|
|
||||||
fn map<T, F: FnOnce(Self) -> T>(self, f: F) -> T
|
fn map<T, F: FnOnce(Self) -> T>(self, f: F) -> T
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
@@ -65,7 +68,7 @@ impl BoolExt for bool {
|
|||||||
fn expect(self, msg: &str) -> Self { self.then_some(true).expect(msg) }
|
fn expect(self, msg: &str) -> Self { self.then_some(true).expect(msg) }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn expect_false(self, msg: &str) -> Self { (!self).then_some(false).expect(msg) }
|
fn expect_false(self, msg: &str) -> Self { self.is_false().then_some(false).expect(msg) }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_option(self) -> Option<()> { self.then_some(()) }
|
fn into_option(self) -> Option<()> { self.then_some(()) }
|
||||||
@@ -73,6 +76,9 @@ impl BoolExt for bool {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn into_result(self) -> Result<(), ()> { self.ok_or(()) }
|
fn into_result(self) -> Result<(), ()> { self.ok_or(()) }
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn is_false(&self) -> Self { self.eq(&false) }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn map<T, F: FnOnce(Self) -> T>(self, f: F) -> T
|
fn map<T, F: FnOnce(Self) -> T>(self, f: F) -> T
|
||||||
where
|
where
|
||||||
@@ -103,10 +109,10 @@ impl BoolExt for bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn or<T, F: FnOnce() -> T>(self, f: F) -> Option<T> { (!self).then(f) }
|
fn or<T, F: FnOnce() -> T>(self, f: F) -> Option<T> { self.is_false().then(f) }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn or_some<T>(self, t: T) -> Option<T> { (!self).then_some(t) }
|
fn or_some<T>(self, t: T) -> Option<T> { self.is_false().then_some(t) }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn then_none<T>(self) -> Option<T> { Option::<T>::None }
|
fn then_none<T>(self) -> Option<T> { Option::<T>::None }
|
||||||
|
|||||||
Reference in New Issue
Block a user