Check if a value is "truthy"
In other words,
rust
// rust
my_value.truthy();
Should behave similarly to
javascript
// javascript
!!myValue;
Boolean(myValue);
or
```python
bool(my_value) ```
```rust // 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: Option<()> = None; let falsyinner = Some(false); let truthyinner = Some(true); none.truthy() // false falsyinner.truthy() // false truthyinner.truthy() // true
// Results are truthy if Ok and value is truthy let falsyerr: Result<(), _> = Err(false); let truthyerr: Result<(), > = Err(true); let falsyok: Result<_, ()> = Ok(false); let truthy_ok: Result<_, ()> = Ok(true);
falsyerr.truthy() // false truthyerr.truthy() // false falsyok.truthy() // false truthyok.truthy() // true
// Empty vecs and arrays are falsy let emptyarray: [();0] = []; let emptyvec: Vec<()> = Vec::new();
emptyarray.truthy() // false emptyvec.truthy() // false
// The truthy behavior of arrays and vecs also applies to tuples from size 0 to 12 let emptytuple = (); let notemptytuple = (1, "2", '3'); emptytuple.truthy() // false notemptytuple.truthy() // true ```