BoolMap

Trait BoolMap 

Source
pub trait BoolMap {
    // Required methods
    fn map<T>(self, value: T) -> Option<T>;
    fn map_with<T, F>(self, f: F) -> Option<T>
       where F: FnMut() -> T;
}
Expand description

Maps bools to Options in one line

§Example

use kai::*;

let condition = true;

// Turn this:
let s = if condition {
    Some(String::new())
} else {
    None
};

// Into this:
let s = condition.map_with(String::new);

assert_eq!(Some(String::new()), s);

Required Methods§

Source

fn map<T>(self, value: T) -> Option<T>

Map to an optional value

Source

fn map_with<T, F>(self, f: F) -> Option<T>
where F: FnMut() -> T,

Map to an optional value using a function

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.

Implementors§

Source§

impl<B> BoolMap for B
where B: Into<bool>,