Skip to main content

InTrue

Trait InTrue 

Source
pub trait InTrue: Sized {
    // Required methods
    fn in_true<F, R>(&mut self, f: F) -> Option<R>
       where F: FnOnce() -> R;
    fn in_false<F, R>(&mut self, f: F) -> Option<R>
       where F: FnOnce() -> R;
}
Expand description
let mut state = false;
let mut n = 0;

assert_eq!(state.in_true(|| n += 1), None);
assert_eq!((n, state), (0, true));

assert_eq!(state.in_true(|| n += 1), Some(()));
assert_eq!((n, state), (1, true));

assert_eq!(state.in_false(|| n += 1), None);
assert_eq!((n, state), (1, false));

assert_eq!(state.in_false(|| n += 1), Some(()));
assert_eq!((n, state), (2, false));

Required Methods§

Source

fn in_true<F, R>(&mut self, f: F) -> Option<R>
where F: FnOnce() -> R,

Run f when *self == true, then assign *self to true

Source

fn in_false<F, R>(&mut self, f: F) -> Option<R>
where F: FnOnce() -> R,

Run f when *self == false, then assign *self to false

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl InTrue for bool

Source§

fn in_true<F, R>(&mut self, f: F) -> Option<R>
where F: FnOnce() -> R,

Source§

fn in_false<F, R>(&mut self, f: F) -> Option<R>
where F: FnOnce() -> R,

Implementors§