Trait stry_common::utils::fenn::BoolExt[][src]

pub trait BoolExt: Copy {
    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<(), ()>; }

Various extensions to the bool primitive.

Required methods

fn some<T>(self, t: T) -> Option<T>[src]

A stable version of then_some.

Returns Some(t) if the bool is true, or None otherwise.

Examples

use fenn::BoolExt;

assert_eq!(false.some(0), None);
assert_eq!(true.some(0), Some(0));

fn some_with<T, F>(self, run: F) -> Option<T> where
    F: FnOnce() -> T, 
[src]

A stable version of then.

Returns Some(f()) if the bool is true, or None otherwise.

Examples

use fenn::BoolExt;

assert_eq!(false.some_with(|| 0), None);
assert_eq!(true.some_with(|| 0), Some(0));

fn as_option(self) -> Option<()>[src]

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());

fn ok<T>(self, t: T) -> Result<T, ()>[src]

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));

fn ok_with<T, F>(self, run: F) -> Result<T, ()> where
    F: FnOnce() -> T, 
[src]

Returns Ok(run()) if the bool is true, or Er(()) otherwise.

Examples

use fenn::BoolExt;

assert_eq!(false.ok_with(|| 0), Err(()));
assert_eq!(true.ok_with(|| 0), Ok(0));

fn as_result(self) -> Result<(), ()>[src]

Returns Ok(()) if the bool is true, or Err(()) otherwise.

Loading content...

Implementations on Foreign Types

impl BoolExt for bool[src]

Loading content...

Implementors

Loading content...