From 5b620a2c37fd912d4c5abf12bd63e0c50a0959c3 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 21 Oct 2025 17:33:25 +0000 Subject: [PATCH] Add `.and_is()` / `.and_if()` to the BoolExt smalltalk. Signed-off-by: Jason Volk --- src/core/utils/bool.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/core/utils/bool.rs b/src/core/utils/bool.rs index 045ee014..66adfa4c 100644 --- a/src/core/utils/bool.rs +++ b/src/core/utils/bool.rs @@ -4,6 +4,12 @@ pub trait BoolExt { fn and(self, t: Option) -> Option; + #[must_use] + fn and_is(self, b: bool) -> bool; + + #[must_use] + fn and_if bool>(self, f: F) -> bool; + fn and_then Option>(self, f: F) -> Option; #[must_use] @@ -55,6 +61,12 @@ impl BoolExt for bool { #[inline] fn and(self, t: Option) -> Option { self.then_some(t).flatten() } + #[inline] + fn and_if Self>(self, f: F) -> Self { self.and_is(f()) } + + #[inline] + fn and_is(self, b: Self) -> Self { self && b } + #[inline] fn and_then Option>(self, f: F) -> Option { self.then(f).flatten() }