Expand description
Check if a value is “truthy”
my_value.truthy();
Enable the and-or
feature to get access to truthy_and
and truthy_or
.
§Behavior
let truthy_option = Some(1u32);
let falsy_options = [None, Some(0u32)];
assert!(truthy_option.truthy());
for falsy_option in &falsy_options {
assert!(falsy_option.falsy());
}
let truthy_result: Result<_, ()> = Ok(1u32);
let falsy_results = [Ok(false), Err(false), Err(true)];
assert!(truthy_result.truthy());
for falsy_result in &falsy_results {
assert!(falsy_result.falsy());
}
let not_empty = vec![()];
let empty: [();0] = [];
assert!(not_empty.truthy());
assert!(empty.falsy());
§Example Usage
use truthy::Truthy;
fn do_something<T: Truthy>(value: T) {
if value.truthy() {
println!("It's truthy :)");
}
}
Macros§
- truthy
- Convenience macro for evaluating truthiness.
Traits§
- Truthy
- Convert to a
bool
.