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§
Sourcefn set(&mut self, val: bool) -> bool
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().
Sourcefn trip(&mut self, val: bool) -> bool
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§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".