From 5c127b5abd3a64b92f6af081def431dfb679d41f Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 3 Oct 2025 06:58:05 +0000 Subject: [PATCH] Add is_false() to BoolExt. Signed-off-by: Jason Volk --- src/core/utils/bool.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/utils/bool.rs b/src/core/utils/bool.rs index 18dd616d..045ee014 100644 --- a/src/core/utils/bool.rs +++ b/src/core/utils/bool.rs @@ -23,6 +23,9 @@ pub trait BoolExt { #[allow(clippy::result_unit_err)] fn into_result(self) -> Result<(), ()>; + #[must_use] + fn is_false(&self) -> Self; + fn map T>(self, f: F) -> T where Self: Sized; @@ -65,7 +68,7 @@ impl BoolExt for bool { fn expect(self, msg: &str) -> Self { self.then_some(true).expect(msg) } #[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] fn into_option(self) -> Option<()> { self.then_some(()) } @@ -73,6 +76,9 @@ impl BoolExt for bool { #[inline] fn into_result(self) -> Result<(), ()> { self.ok_or(()) } + #[inline] + fn is_false(&self) -> Self { self.eq(&false) } + #[inline] fn map T>(self, f: F) -> T where @@ -103,10 +109,10 @@ impl BoolExt for bool { } #[inline] - fn or T>(self, f: F) -> Option { (!self).then(f) } + fn or T>(self, f: F) -> Option { self.is_false().then(f) } #[inline] - fn or_some(self, t: T) -> Option { (!self).then_some(t) } + fn or_some(self, t: T) -> Option { self.is_false().then_some(t) } #[inline] fn then_none(self) -> Option { Option::::None }