Trait aoko::no_std::functions::ext::BoolExt[][src]

pub trait BoolExt<R> {
    fn if_true(self, value: R) -> Option<R>;
fn if_false(self, value: R) -> Option<R>;
fn then_false(self, f: impl FnOnce() -> R) -> Option<R>; }
Expand description

This trait is to implement some extension functions for bool type.

Required methods

Implementations on Foreign Types

Chainable if, returns Some(value) when the condition is true

Examples
use aoko::no_std::functions::ext::*;

let s = "Hello World";
assert_eq!(Some("lo Wo"), s.starts_with("Hel").if_true(&s[3..8]));
assert_eq!(None, s.starts_with("Wor").if_true(&s[3..8]));

Chainable if, returns Some(value) when the condition is false

Examples
use aoko::no_std::functions::ext::*;

let s = "Hello World";
assert_eq!(None, s.starts_with("Hel").if_false(&s[3..8]));
assert_eq!(Some("lo Wo"), s.starts_with("Wor").if_false(&s[3..8]));

Returns Some(f()) if the receiver is false, or None otherwise

Examples
use aoko::no_std::functions::ext::*;

let s = "Hello World";

// then:
assert_eq!(Some("lo Wo"), s.starts_with("Hel").then(|| &s[3..8]));
assert_eq!(None, s.starts_with("Wor").then(|| &s[3..8]));

// then_false:
assert_eq!(None, s.starts_with("Hel").then_false(|| &s[3..8]));
assert_eq!(Some("lo Wo"), s.starts_with("Wor").then_false(|| &s[3..8]));

Implementors