Some

Trait Some 

Source
pub trait Some {
    // Required methods
    fn some<T>(self, t: T) -> Option<T>;
    fn some_with<T, F>(self, f: F) -> Option<T>
       where F: FnOnce() -> T;
}
Expand description

Provides the some and some_with methods on bool.

Required Methods§

Source

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

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

Arguments passed to some are eagerly evaluated; if you are passing the result of a function call, it is recommended to use some_with, which is lazily evaluated.

§Examples
use then::Some;

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

fn some_with<T, F>(self, f: F) -> Option<T>
where F: FnOnce() -> T,

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

§Examples
use then::Some;

assert_eq!(false.some_with(|| 0), None);
assert_eq!(true.some_with(Default::default), Some(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.

Implementations on Foreign Types§

Source§

impl Some for bool

Source§

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

Source§

fn some_with<T, F>(self, f: F) -> Option<T>
where F: FnOnce() -> T,

Implementors§