diff --git a/src/core/utils/bool.rs b/src/core/utils/bool.rs index fed8774b..18dd616d 100644 --- a/src/core/utils/bool.rs +++ b/src/core/utils/bool.rs @@ -23,10 +23,6 @@ pub trait BoolExt { #[allow(clippy::result_unit_err)] fn into_result(self) -> Result<(), ()>; - fn then_ok_or(self, t: T, e: E) -> Result; - - fn then_ok_or_else E>(self, t: T, e: F) -> Result; - fn map T>(self, f: F) -> T where Self: Sized; @@ -44,6 +40,12 @@ pub trait BoolExt { fn or T>(self, f: F) -> Option; fn or_some(self, t: T) -> Option; + + fn then_none(self) -> Option; + + fn then_ok_or(self, t: T, e: E) -> Result; + + fn then_ok_or_else E>(self, t: T, e: F) -> Result; } impl BoolExt for bool { @@ -71,14 +73,6 @@ impl BoolExt for bool { #[inline] fn into_result(self) -> Result<(), ()> { self.ok_or(()) } - #[inline] - fn then_ok_or(self, t: T, e: E) -> Result { self.map_ok_or(e, move || t) } - - #[inline] - fn then_ok_or_else E>(self, t: T, e: F) -> Result { - self.ok_or_else(e).map(move |()| t) - } - #[inline] fn map T>(self, f: F) -> T where @@ -113,4 +107,15 @@ impl BoolExt for bool { #[inline] fn or_some(self, t: T) -> Option { (!self).then_some(t) } + + #[inline] + fn then_none(self) -> Option { Option::::None } + + #[inline] + fn then_ok_or(self, t: T, e: E) -> Result { self.map_ok_or(e, move || t) } + + #[inline] + fn then_ok_or_else E>(self, t: T, e: F) -> Result { + self.ok_or_else(e).map(move |()| t) + } }