env_parse_bool

Function env_parse_bool 

Source
pub fn env_parse_bool(env: &str) -> Result<Option<bool>>
Expand description

Parse an environment variable as a boolean, returning an error if invalid.

§Arguments

  • env - The environment variable name

§Returns

  • Ok(Some(true)) - If the env var is set to a truthy value
  • Ok(Some(false)) - If the env var is set to a falsey value
  • Ok(None) - If the env var is not set
  • Err(_) - If the env var is set to an invalid value

§Example

match env_parse_bool("MY_FLAG")? {
    Some(true) => println!("enabled"),
    Some(false) => println!("disabled"),
    None => println!("not configured"),
}