Skip to main content

Crate to_true

Crate to_true 

Source
Expand description

Convenient conversion of bool states

§Examples

let mut state = false;
let mut n = 0;

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

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

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

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

Traits§

InTrue
ToTrue
Convenient conversion of bool states

Functions§

once
A closure that is runs only once
skip
A closure that does not run on the first call