additional stream tools
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
a8d5cf9651
commit
6b80361c31
10 changed files with 242 additions and 46 deletions
16
src/core/utils/bool.rs
Normal file
16
src/core/utils/bool.rs
Normal 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) }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue