additional stream tools

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-09-30 06:46:54 +00:00 committed by strawberry
parent a8d5cf9651
commit 6b80361c31
10 changed files with 242 additions and 46 deletions

16
src/core/utils/bool.rs Normal file
View file

@ -0,0 +1,16 @@
//! Trait BoolExt
/// Boolean extensions and chain.starters
pub trait BoolExt {
fn or<T, F: FnOnce() -> T>(self, f: F) -> Option<T>;
fn or_some<T>(self, t: T) -> Option<T>;
}
impl BoolExt for bool {
#[inline]
fn or<T, F: FnOnce() -> T>(self, f: F) -> Option<T> { (!self).then(f) }
#[inline]
fn or_some<T>(self, t: T) -> Option<T> { (!self).then_some(t) }
}