truthy
Check if a value is "truthy"
In other words,
// rust
my_value.truthy;
Should behave similarly to
// javascript
!!myValue;
Boolean;
or
# python
Behavior
// non-zero numbers are truthy
0u32.truthy // false
0f32.truthy // false
1u32.truthy // true
1f32.truthy // true
// empty strings are not truthy
"".truthy // false
" ".truthy // true
// Options are truthy if not None and their value is truthy
let none: = None;
let falsy_inner = Some;
let truthy_inner = Some;
none.truthy // false
falsy_inner.truthy // false
truthy_inner.truthy // true
// Results are truthy if Ok and value is truthy
let falsy_err: = Err;
let truthy_err: = Err;
let falsy_ok: = Ok;
let truthy_ok: = Ok;
falsy_err.truthy // false
truthy_err.truthy // false
falsy_ok.truthy // false
truthy_ok.truthy // true
// Empty vecs and arrays are falsy
let empty_array: = ;
let empty_vec: = Vec new;
empty_array.truthy // false
empty_vec.truthy // false
// The truthy behavior of arrays and vecs also applies to tuples from size 0 to 12
let empty_tuple = ;
let not_empty_tuple = ;
empty_tuple.truthy // false
not_empty_tuple.truthy // true