| Crates.io | truthy |
| lib.rs | truthy |
| version | 2.0.0 |
| created_at | 2020-08-06 13:15:07.567647+00 |
| updated_at | 2026-01-09 23:12:54.707477+00 |
| description | Check if a value is "truthy" |
| homepage | |
| repository | https://github.com/spenserblack/truthy-rs |
| max_upload_size | |
| id | 273653 |
| size | 25,026 |
Check if a value is "truthy"
let choice: String = get_user_input();
// `choice` is the original choice if it's truthy (non-empty string), or the default
// choice if it's falsy (empty string).
let choice = choice.or(String::from("default choice"));
// Decrements n by 1 if n > 0;
let mut n = get_u8();
n.and_then_eq(|n| n - 1);
// non-zero numbers are truthy
0u32.truthy(); // false
0f32.truthy(); // false
1u32.truthy(); // true
1f32.truthy(); // true
// empty strings are not truthy
"".truthy(); // false
"foo".truthy(); // true