pub const fn parse_bool(s: &str) -> Result<bool, ParseBoolError>Expand description
Parses a bool from a &str.
This returns an Err if the string would not successfully .parse() into a bool.
To parse a bool from only part of a string, you can use Parser::parse_bool.
ยงExample
use konst::{
primitive::{ParseBoolResult, parse_bool},
unwrap_ctx,
};
const T: ParseBoolResult = parse_bool("true");
const F: ParseBoolResult = parse_bool("false");
assert_eq!(T, Ok(true));
assert_eq!(F, Ok(false));
// This is how you can unwrap bools parsed from strings, at compile-time.
const T2: bool = unwrap_ctx!(parse_bool("true"));
const F2: bool = unwrap_ctx!(parse_bool("false"));
assert_eq!(T2, true);
assert_eq!(F2, false);
assert!(parse_bool("0").is_err());
assert!(parse_bool("FALSE").is_err());