humanbool

Crates.iohumanbool
lib.rshumanbool
version1.3.0
sourcesrc
created_at2016-07-25 19:07:39.614773
updated_at2021-05-09 17:30:09.246514
descriptionParse human-entered booleans.
homepagehttps://github.com/kevincox/humanbool.rs
repositoryhttps://github.com/kevincox/humanbool.rs
max_upload_size
id5786
size3,963
Kevin Cox (kevincox)

documentation

README

Human Bool (for Rust)

A simple library to parse human entered booleans, especially those from environment variables.

Currently the following strings are supported:

  • 1/0
  • yes/no/y/n
  • true/false/t/f
  • on/off

From a string

use humanbool::parse;
assert!(parse("y") == Ok(true));

From the environment.

use humanbool::*;
assert_eq!(env("ENABLE_KITTENS", "f"), Ok(false));
std::env::set_var("ENABLE_KITTENS", "1");
assert!(env("ENABLE_KITTENS", "f") == Ok(true));

assert!(env("ENABLE_TURBO", "") == Err(Error::Empty));
Commit count: 3

cargo fmt