From 45da0c030ec0dd1633a46f363a5c8b7cc710ac8e Mon Sep 17 00:00:00 2001 From: Nils Andreas Svee Date: Wed, 22 Apr 2026 16:54:52 +0700 Subject: [PATCH] feat: Add flexible boolean parsing for configuration --- src/config.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/config.rs b/src/config.rs index 5628d37..0b070ea 100644 --- a/src/config.rs +++ b/src/config.rs @@ -35,6 +35,26 @@ where Ok(io::BufReader::new(file).lines()) } +struct FlexiBool(bool); + +impl FromStr for FlexiBool { + type Err = ConfigError; + + fn from_str(s: &str) -> Result { + 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 for bool { + fn from(f: FlexiBool) -> bool { + f.0 + } +} + #[derive(Clone, Copy, Debug)] pub enum MeasurementType { Icmp = 1,