mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-13 18:02:00 -04:00
TryFrom on enums should use anyhow::Error as the error type
This commit is contained in:
parent
3cd834b385
commit
d465bc2750
4 changed files with 16 additions and 16 deletions
14
src/wifi.rs
14
src/wifi.rs
|
@ -5,7 +5,7 @@
|
|||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
use anyhow::{bail, ensure, Result};
|
||||
use anyhow::{anyhow, bail, ensure, Error, Result};
|
||||
use std::str::FromStr;
|
||||
use strum::{Display, EnumString};
|
||||
use tokio::fs;
|
||||
|
@ -75,34 +75,34 @@ pub enum WifiBackend {
|
|||
}
|
||||
|
||||
impl TryFrom<u32> for WifiDebugMode {
|
||||
type Error = String;
|
||||
type Error = Error;
|
||||
fn try_from(v: u32) -> Result<Self, Self::Error> {
|
||||
match v {
|
||||
x if x == WifiDebugMode::Off as u32 => Ok(WifiDebugMode::Off),
|
||||
x if x == WifiDebugMode::Tracing as u32 => Ok(WifiDebugMode::Tracing),
|
||||
_ => Err(format!("No enum match for value {v}")),
|
||||
_ => Err(anyhow!("No enum match for value {v}")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<u32> for WifiPowerManagement {
|
||||
type Error = String;
|
||||
type Error = Error;
|
||||
fn try_from(v: u32) -> Result<Self, Self::Error> {
|
||||
match v {
|
||||
x if x == WifiPowerManagement::Disabled as u32 => Ok(WifiPowerManagement::Disabled),
|
||||
x if x == WifiPowerManagement::Enabled as u32 => Ok(WifiPowerManagement::Enabled),
|
||||
_ => Err(format!("No enum match for value {v}")),
|
||||
_ => Err(anyhow!("No enum match for value {v}")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<u32> for WifiBackend {
|
||||
type Error = String;
|
||||
type Error = Error;
|
||||
fn try_from(v: u32) -> Result<Self, Self::Error> {
|
||||
match v {
|
||||
x if x == WifiBackend::Iwd as u32 => Ok(WifiBackend::Iwd),
|
||||
x if x == WifiBackend::WPASupplicant as u32 => Ok(WifiBackend::WPASupplicant),
|
||||
_ => Err(format!("No enum match for WifiBackend value {v}")),
|
||||
_ => Err(anyhow!("No enum match for WifiBackend value {v}")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue