diff --git a/src/core/utils/bool.rs b/src/core/utils/bool.rs index b4192daf..b16f63e9 100644 --- a/src/core/utils/bool.rs +++ b/src/core/utils/bool.rs @@ -2,6 +2,10 @@ /// Boolean extensions and chain.starters pub trait BoolExt { + fn and(self, t: Option) -> Option; + + fn and_then Option>(self, f: F) -> Option; + #[must_use] fn clone_or(self, err: T, t: &T) -> T; @@ -39,6 +43,12 @@ pub trait BoolExt { } impl BoolExt for bool { + #[inline] + fn and(self, t: Option) -> Option { self.then_some(t).flatten() } + + #[inline] + fn and_then Option>(self, f: F) -> Option { self.then(f).flatten() } + #[inline] fn clone_or(self, err: T, t: &T) -> T { self.map_or(err, || t.clone()) }