pub trait BoolExt: TypeIdentity<Type = bool> + Sized {
// Provided methods
fn if_true<T, F>(self, some: F) -> Option<T>
where F: FnOnce() -> T { ... }
fn if_false<T, F>(self, some: F) -> Option<T>
where F: FnOnce() -> T { ... }
}Available on crate feature
bools only.Expand description
Extension trait for bool.
Provided Methods§
Sourcefn if_true<T, F>(self, some: F) -> Option<T>where
F: FnOnce() -> T,
fn if_true<T, F>(self, some: F) -> Option<T>where
F: FnOnce() -> T,
Returns Some(some()) if self is true, otherwise returns None.
This method is usable in all versions supported by this library,
and is equivalent to the bool::then method, which was stabilized in Rust 1.50.
§Example
use core_extensions::BoolExt;
assert_eq!(true .if_true(|| 100 ), Some(100));
assert_eq!(false.if_true(|| 100 ), None);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.