From 368ead20a611f65aa5bde297b605d17892916bca Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 30 Sep 2025 00:57:25 +0000 Subject: [PATCH] Add then_none() to BoolExt; move unsorted then_ utils. Signed-off-by: Jason Volk --- src/core/utils/bool.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) 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) + } }