From 936bdb220ca75cd490addb788326797a5702cfe0 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Mon, 13 May 2024 16:44:57 -0700 Subject: [PATCH] wifi: Add WifiDebugMode::from_str and WifiPowerManagement::from_str --- src/wifi.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/wifi.rs b/src/wifi.rs index 523a3a9..33af2ae 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -64,6 +64,17 @@ impl TryFrom for WifiDebugMode { } } +impl FromStr for WifiDebugMode { + type Err = Error; + fn from_str(input: &str) -> Result { + Ok(match input { + "enable" | "enabled" | "on" | "1" => WifiDebugMode::On, + "disable" | "disabled" | "off" | "0" => WifiDebugMode::Off, + v => bail!("No enum match for value {v}"), + }) + } +} + impl fmt::Display for WifiDebugMode { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { @@ -84,6 +95,17 @@ impl TryFrom for WifiPowerManagement { } } +impl FromStr for WifiPowerManagement { + type Err = Error; + fn from_str(input: &str) -> Result { + Ok(match input { + "enable" | "enabled" | "on" | "1" => WifiPowerManagement::Enabled, + "disable" | "disabled" | "off" | "0" => WifiPowerManagement::Disabled, + v => bail!("No enum match for value {v}"), + }) + } +} + impl fmt::Display for WifiPowerManagement { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self {