truthy

Crates.iotruthy
lib.rstruthy
version2.0.0
created_at2020-08-06 13:15:07.567647+00
updated_at2026-01-09 23:12:54.707477+00
descriptionCheck if a value is "truthy"
homepage
repositoryhttps://github.com/spenserblack/truthy-rs
max_upload_size
id273653
size25,026
Spenser Black (spenserblack)

documentation

README

truthy

Crates.io Docs.rs

Check if a value is "truthy"

Example

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);

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
"foo".truthy(); // true
Commit count: 77

cargo fmt