feat: Add flexible boolean parsing for configuration

This commit is contained in:
Nils Andreas Svee committed 2026-04-22 16:55:05 +07:00
1 parent 33169182be
commit 45da0c030e
1 file changed
+20
+20
View File
@@ -35,6 +35,26 @@ where
Ok(io::BufReader::new(file).lines()) Ok(io::BufReader::new(file).lines())
} }
struct FlexiBool(bool);
impl FromStr for FlexiBool {
type Err = ConfigError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.trim().to_lowercase().as_str() {
"1" | "true" | "yes" | "y" | "on" | "enabled" => Ok(FlexiBool(true)),
"0" | "false" | "no" | "n" | "off" | "disabled" => Ok(FlexiBool(false)),
_ => Err(ConfigError::ParseError(s.to_string())),
}
}
}
impl From<FlexiBool> for bool {
fn from(f: FlexiBool) -> bool {
f.0
}
}
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub enum MeasurementType { pub enum MeasurementType {
Icmp = 1, Icmp = 1,