Trait core_extensions::BoolExt [−][src]
pub trait BoolExt: TypeIdentity<Type = bool> + Sized { 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, { ... } }
This is supported on crate feature
bools only.Extension trait for bool.
Provided methods
fn if_true<T, F>(self, some: F) -> Option<T> where
F: FnOnce() -> T, [src]
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);
fn if_false<T, F>(self, some: F) -> Option<T> where
F: FnOnce() -> T, [src]
F: FnOnce() -> T,
Returns Some(some()) if self is false, otherwise returns None.
Example
use core_extensions::BoolExt; assert_eq!(false.if_false(|| 100 ), Some(100)); assert_eq!(true .if_false(|| 100 ), None);