pub fn parse_bool(val: &str) -> Result<bool>Expand description
Parse a string as a boolean value, returning an error if invalid.
This function strictly validates that the input is a valid boolean representation.
§Arguments
val- The string value to parse
§Returns
Ok(true)- For truthy values: “1”, “true”, “on”, “yes” (case-insensitive)Ok(false)- For falsey values: “0”, “false”, “off”, “no” (case-insensitive)Err(_)- For any other value
§Example
ⓘ
assert_eq!(parse_bool("true")?, true);
assert_eq!(parse_bool("0")?, false);
assert!(parse_bool("maybe").is_err());