Trait PowerBool

Source
pub trait PowerBool {
    // Required methods
    fn set(&mut self, val: bool) -> bool;
    fn trip(&mut self, val: bool) -> bool;

    // Provided methods
    fn raise(&mut self) -> bool { ... }
    fn lower(&mut self) -> bool { ... }
    fn kick(&mut self) -> bool { ... }
    fn punch(&mut self) -> bool { ... }
}
Expand description

This trait adds ergonomic convenience functions to bool.

Required Methods§

Source

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

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§

Source

fn raise(&mut self) -> bool

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

Source

fn lower(&mut self) -> bool

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

Source

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?)

Source

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?)

Implementations on Foreign Types§

Source§

impl PowerBool for bool

Source§

fn set(&mut self, val: bool) -> bool

Source§

fn trip(&mut self, val: bool) -> bool

Implementors§