wifi: Add WifiDebugMode::from_str and WifiPowerManagement::from_str

This commit is contained in:
Vicki Pfau 2024-05-13 16:44:57 -07:00
parent 20227416e1
commit 936bdb220c

View file

@ -64,6 +64,17 @@ impl TryFrom<u32> for WifiDebugMode {
}
}
impl FromStr for WifiDebugMode {
type Err = Error;
fn from_str(input: &str) -> Result<WifiDebugMode, Self::Err> {
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<u32> for WifiPowerManagement {
}
}
impl FromStr for WifiPowerManagement {
type Err = Error;
fn from_str(input: &str) -> Result<WifiPowerManagement, Self::Err> {
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 {