pub fn parse_str_as_bool(string: &str) -> Result<bool>Expand description
Parses a string to a boolean value.
Accepts common boolean representations (case-insensitive):
trueor"1"→truefalseor"0"→false
§Arguments
string- The string to parse
§Returns
Returns Ok(bool) if the string is a valid boolean representation, or
Err if the string cannot be parsed.
§Examples
assert_eq!(parse_str_as_bool("true").unwrap(), true);
assert_eq!(parse_str_as_bool("1").unwrap(), true);
assert_eq!(parse_str_as_bool("FALSE").unwrap(), false);
assert_eq!(parse_str_as_bool("0").unwrap(), false);
assert!(parse_str_as_bool("maybe").is_err());