Trait powerbool::PowerBool
[−]
[src]
pub trait PowerBool { fn set(&mut self, val: bool) -> bool; fn trip(&mut self, val: bool) -> bool; fn raise(&mut self) -> bool { ... } fn lower(&mut self) -> bool { ... } fn kick(&mut self) -> bool { ... } fn punch(&mut self) -> bool { ... } }
This trait adds ergonomic convenience functions to bool
.
Required Methods
fn set(&mut self, val: bool) -> bool
Set the value, and say if it changed.
Don't use a boolean literal with this function, val
should be an expression:
- Instead of
set(true)
, useraise()
. - Instead of
set(false)
, uselower()
.
fn trip(&mut self, val: bool) -> bool
Returns true
if the value was false
. This is not the same as set()
.
use powerbool::PowerBool; let list = vec![0.23, 3.4, 8.0, 9.6]; let mut found = false; for x in list { if found.trip((x as i32 as f32) == x) { println!("Alert! There's an integer hiding in our number!"); return; } } println!("Nobody here but us floats.");
Provided Methods
fn raise(&mut self) -> bool
Set the value to true
, and say if it changed.
fn lower(&mut self) -> bool
Set the value to false
, and say if it changed.
fn kick(&mut self) -> bool
Makes sure the value is false
, and return true
if it didn`t change.
(Am I kicking a dead horse?)
fn punch(&mut self) -> bool
Makes sure the value is true
, and return true
if it didn't change.
(The opposite of kick
: am I punching a sleeping horse?)
Implementors
impl PowerBool for bool