mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-15 21:26:50 +00:00
Add .and_is() / .and_if() to the BoolExt smalltalk.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
1 parent
3b4fbb8c1a
commit
5b620a2c37
1 file changed
+12
@@ -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() }
|
||||
|
||||
|
||||
Reference in new issue
Block a user