Fix clippy warnings, and an actual bug with FanControl::try_from<u32>

This commit is contained in:
Vicki Pfau 2024-04-05 15:26:09 -07:00
parent 9d7ee926f4
commit b962bbf548
6 changed files with 21 additions and 21 deletions

View file

@ -168,7 +168,7 @@ async fn main() -> Result<()> {
let mut log_receiver = LogReceiver::new(connection.clone()).await?;
let remote_logger = LogLayer::new(&log_receiver).await;
let subscriber = subscriber.with(remote_logger);
let _guard = tracing::subscriber::set_global_default(subscriber)?;
tracing::subscriber::set_global_default(subscriber)?;
let mut sigterm = signal(SignalKind::terminate())?;
let mut sigquit = signal(SignalKind::quit())?;

View file

@ -36,16 +36,16 @@ enum PrepareFactoryReset {
#[derive(PartialEq, Debug, Copy, Clone)]
#[repr(u32)]
enum FanControl {
BIOS = 0,
OS = 1,
Bios = 0,
Os = 1,
}
impl TryFrom<u32> for FanControl {
type Error = &'static str;
fn try_from(v: u32) -> Result<Self, Self::Error> {
match v {
x if x == FanControl::BIOS as u32 => Ok(FanControl::BIOS),
x if x == FanControl::OS as u32 => Ok(FanControl::BIOS),
x if x == FanControl::Bios as u32 => Ok(FanControl::Bios),
x if x == FanControl::Os as u32 => Ok(FanControl::Os),
_ => Err("No enum match for value {v}"),
}
}
@ -54,8 +54,8 @@ impl TryFrom<u32> for FanControl {
impl fmt::Display for FanControl {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
FanControl::BIOS => write!(f, "BIOS"),
FanControl::OS => write!(f, "OS"),
FanControl::Bios => write!(f, "BIOS"),
FanControl::Os => write!(f, "OS"),
}
}
}
@ -138,8 +138,8 @@ impl SteamOSManager {
.await
.map_err(anyhow_to_zbus_fdo)?;
Ok(match active {
true => FanControl::OS as u32,
false => FanControl::BIOS as u32,
true => FanControl::Os as u32,
false => FanControl::Bios as u32,
})
}
@ -155,8 +155,8 @@ impl SteamOSManager {
.await
.map_err(anyhow_to_zbus)?;
match state {
FanControl::OS => jupiter_fan_control.start().await,
FanControl::BIOS => jupiter_fan_control.stop().await,
FanControl::Os => jupiter_fan_control.start().await,
FanControl::Bios => jupiter_fan_control.stop().await,
}
.map_err(anyhow_to_zbus)
}
@ -336,7 +336,7 @@ impl SteamOSManager {
// doing things on 0 or 1 for now
// Return false on error
match get_wifi_backend().await {
Ok(WifiBackend::IWD) => (),
Ok(WifiBackend::Iwd) => (),
Ok(backend) => {
return Err(zbus::fdo::Error::Failed(format!(
"Setting wifi debug mode not supported when backend is {backend}",

View file

@ -80,7 +80,7 @@ pub async fn get_gpu_performance_level() -> Result<GPUPerformanceLevel> {
.await
.inspect_err(|message| error!("Error opening sysfs file for reading: {message}"))?;
GPUPerformanceLevel::from_str(level.trim().as_ref())
GPUPerformanceLevel::from_str(level.trim())
}
pub async fn set_gpu_performance_level(level: GPUPerformanceLevel) -> Result<()> {

View file

@ -44,7 +44,7 @@ impl Ftrace {
pub async fn init(connection: Connection) -> Result<Ftrace> {
let path = Self::base();
fs::create_dir_all(&path).await?;
setup_traces(&path.as_path()).await?;
setup_traces(path.as_path()).await?;
let file = pipe::OpenOptions::new()
.unchecked(true) // Thanks tracefs for making trace_pipe a "regular" file
.open_receiver(path.join("trace_pipe"))?;

View file

@ -37,7 +37,7 @@ pub struct SystemdUnit<'dbus> {
}
pub async fn daemon_reload(connection: &Connection) -> Result<()> {
let proxy = SystemdManagerProxy::new(&connection).await?;
let proxy = SystemdManagerProxy::new(connection).await?;
proxy.reload().await?;
Ok(())
}

View file

@ -49,7 +49,7 @@ pub enum WifiPowerManagement {
#[derive(PartialEq, Debug, Copy, Clone)]
#[repr(u32)]
pub enum WifiBackend {
IWD = 0,
Iwd = 0,
WPASupplicant = 1,
}
@ -97,7 +97,7 @@ impl TryFrom<u32> for WifiBackend {
type Error = &'static str;
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::Iwd as u32 => Ok(WifiBackend::Iwd),
x if x == WifiBackend::WPASupplicant as u32 => Ok(WifiBackend::WPASupplicant),
_ => Err("No enum match for WifiBackend value {v}"),
}
@ -108,7 +108,7 @@ impl FromStr for WifiBackend {
type Err = Error;
fn from_str(input: &str) -> Result<WifiBackend, Self::Err> {
Ok(match input {
"iwd" => WifiBackend::IWD,
"iwd" => WifiBackend::Iwd,
"wpa_supplicant" => WifiBackend::WPASupplicant,
_ => bail!("Unknown backend"),
})
@ -118,7 +118,7 @@ impl FromStr for WifiBackend {
impl fmt::Display for WifiBackend {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
WifiBackend::IWD => write!(f, "iwd"),
WifiBackend::Iwd => write!(f, "iwd"),
WifiBackend::WPASupplicant => write!(f, "wpa_supplicant"),
}
}
@ -247,7 +247,7 @@ mod test {
#[tokio::test]
async fn test_wifi_backend_to_string() {
assert_eq!(WifiBackend::IWD.to_string(), "iwd");
assert_eq!(WifiBackend::Iwd.to_string(), "iwd");
assert_eq!(WifiBackend::WPASupplicant.to_string(), "wpa_supplicant");
}
@ -274,7 +274,7 @@ mod test {
write(path(WIFI_BACKEND_PATH), "[device]\nwifi.backend=iwd\n")
.await
.expect("write");
assert_eq!(get_wifi_backend().await.unwrap(), WifiBackend::IWD);
assert_eq!(get_wifi_backend().await.unwrap(), WifiBackend::Iwd);
write(
path(WIFI_BACKEND_PATH),