pub trait BoolExt: Copy {
// Required methods
fn some<T>(self, t: T) -> Option<T>;
fn some_with<T, F>(self, run: F) -> Option<T>
where F: FnOnce() -> T;
fn as_option(self) -> Option<()>;
fn ok<T>(self, t: T) -> Result<T, ()>;
fn ok_with<T, F>(self, run: F) -> Result<T, ()>
where F: FnOnce() -> T;
fn as_result(self) -> Result<(), ()>;
}Expand description
Various extensions to the bool primitive.
Required Methods§
Sourcefn as_option(self) -> Option<()>
fn as_option(self) -> Option<()>
Returns Some(()) if the bool is true, or None otherwise.
§Examples
use fenn::BoolExt;
assert!(false.as_option().is_none());
assert!(true.as_option().is_some());Sourcefn ok<T>(self, t: T) -> Result<T, ()>
fn ok<T>(self, t: T) -> Result<T, ()>
Returns Ok(t) if the bool is true, or Er(()) otherwise.
§Examples
use fenn::BoolExt;
assert_eq!(false.ok(0), Err(()));
assert_eq!(true.ok(0), Ok(0));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.