boolinator

Trait Boolinator

Source
pub trait Boolinator: Sized {
    // Required methods
    fn as_option(self) -> Option<()>;
    fn as_some<T>(self, some: T) -> Option<T>;
    fn as_some_from<T, F>(self, some: F) -> Option<T>
       where F: FnOnce() -> T;
    fn and_option<T>(self, opt: Option<T>) -> Option<T>;
    fn and_option_from<T, F>(self, opt: F) -> Option<T>
       where F: FnOnce() -> Option<T>;
    fn as_result<T, E>(self, ok: T, err: E) -> Result<T, E>;
    fn as_result_from<T, E, F, G>(self, ok: F, err: G) -> Result<T, E>
       where F: FnOnce() -> T,
             G: FnOnce() -> E;
    fn ok_or<E>(self, err: E) -> Result<(), E>;
    fn ok_or_else<E, G>(self, err: G) -> Result<(), E>
       where G: FnOnce() -> E;
    fn expect(self, msg: &str);
}
Expand description

This trait defines a number of combinator-style methods for use with bool values.

In general, true/false map to Some(_)/None and Ok(_)/Err(_) respectively.

Required Methods§

Source

fn as_option(self) -> Option<()>

If this value is true, returns Some(()); None otherwise.

Source

fn as_some<T>(self, some: T) -> Option<T>

If this value is true, returns Some(some); None otherwise.

Source

fn as_some_from<T, F>(self, some: F) -> Option<T>
where F: FnOnce() -> T,

If this value is true, returns Some(some()); None otherwise.

Source

fn and_option<T>(self, opt: Option<T>) -> Option<T>

If this value is true, returns opt; None otherwise.

Source

fn and_option_from<T, F>(self, opt: F) -> Option<T>
where F: FnOnce() -> Option<T>,

If this value is true, returns opt(); None otherwise.

Source

fn as_result<T, E>(self, ok: T, err: E) -> Result<T, E>

If this value is true, returns Ok(ok); Err(err) otherwise.

Source

fn as_result_from<T, E, F, G>(self, ok: F, err: G) -> Result<T, E>
where F: FnOnce() -> T, G: FnOnce() -> E,

If this value is true, returns Ok(ok()); Err(err()) otherwise.

Source

fn ok_or<E>(self, err: E) -> Result<(), E>

If this value is true, returns Ok(()); Err(err) otherwise.

Source

fn ok_or_else<E, G>(self, err: G) -> Result<(), E>
where G: FnOnce() -> E,

If this value is true, returns Ok(()); Err(err()) otherwise.

Source

fn expect(self, msg: &str)

If this value is true, panics with msg; does nothing otherwise.

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.

Implementations on Foreign Types§

Source§

impl Boolinator for bool

Source§

fn as_option(self) -> Option<()>

Source§

fn as_some<T>(self, some: T) -> Option<T>

Source§

fn as_some_from<T, F>(self, some: F) -> Option<T>
where F: FnOnce() -> T,

Source§

fn and_option<T>(self, opt: Option<T>) -> Option<T>

Source§

fn and_option_from<T, F>(self, opt: F) -> Option<T>
where F: FnOnce() -> Option<T>,

Source§

fn as_result<T, E>(self, ok: T, err: E) -> Result<T, E>

Source§

fn as_result_from<T, E, F, G>(self, ok: F, err: G) -> Result<T, E>
where F: FnOnce() -> T, G: FnOnce() -> E,

Source§

fn ok_or<E>(self, err: E) -> Result<(), E>

Source§

fn ok_or_else<E, G>(self, err: G) -> Result<(), E>
where G: FnOnce() -> E,

Source§

fn expect(self, msg: &str)

Implementors§