truthy 2.0.0

Check if a value is "truthy"
Documentation
  • Coverage
  • 100%
    12 out of 12 items documented9 out of 12 items with examples
  • Size
  • Source code size: 24.52 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.59 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • spenserblack/truthy-rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • spenserblack

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