Add .and_is() / .and_if() to the BoolExt smalltalk.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
3b4fbb8c1a
commit
5b620a2c37
1 changed files with 12 additions and 0 deletions
|
|
@ -4,6 +4,12 @@
|
|||
pub trait BoolExt {
|
||||
fn and<T>(self, t: Option<T>) -> Option<T>;
|
||||
|
||||
#[must_use]
|
||||
fn and_is(self, b: bool) -> bool;
|
||||
|
||||
#[must_use]
|
||||
fn and_if<F: FnOnce() -> bool>(self, f: F) -> bool;
|
||||
|
||||
fn and_then<T, F: FnOnce() -> Option<T>>(self, f: F) -> Option<T>;
|
||||
|
||||
#[must_use]
|
||||
|
|
@ -55,6 +61,12 @@ impl BoolExt for bool {
|
|||
#[inline]
|
||||
fn and<T>(self, t: Option<T>) -> Option<T> { self.then_some(t).flatten() }
|
||||
|
||||
#[inline]
|
||||
fn and_if<F: FnOnce() -> Self>(self, f: F) -> Self { self.and_is(f()) }
|
||||
|
||||
#[inline]
|
||||
fn and_is(self, b: Self) -> Self { self && b }
|
||||
|
||||
#[inline]
|
||||
fn and_then<T, F: FnOnce() -> Option<T>>(self, f: F) -> Option<T> { self.then(f).flatten() }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue