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

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), use raise().
  • Instead of set(false), use lower().

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

Set the value to true, and say if it changed.

Set the value to false, and say if it changed.

Makes sure the value is false, and return true if it didn`t change. (Am I kicking a dead horse?)

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