From 616fb3aea6f695cf01bff62879148ae07362e7c1 Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Mon, 5 Dec 2022 20:31:39 +1300 Subject: [PATCH] chore: cranky cleanups --- asusctl/examples/anime-diag.rs | 2 +- asusctl/examples/anime-grid.rs | 1 - asusctl/examples/anime-spinning.rs | 2 +- asusctl/examples/aura-rgb-ball.rs | 6 ++-- asusctl/src/main.rs | 21 +++++++------- daemon/src/config.rs | 4 +-- daemon/src/ctrl_anime/config.rs | 8 +++--- daemon/src/ctrl_aura/config.rs | 43 ++++++++++++++--------------- daemon/src/ctrl_aura/controller.rs | 14 +++++----- daemon/src/ctrl_aura/trait_impls.rs | 2 +- daemon/src/laptops.rs | 2 +- rog-control-center/src/tray.rs | 2 +- rog-profiles/src/lib.rs | 11 ++++---- 13 files changed, 56 insertions(+), 62 deletions(-) diff --git a/asusctl/examples/anime-diag.rs b/asusctl/examples/anime-diag.rs index 5599ce9f..bcbc584c 100644 --- a/asusctl/examples/anime-diag.rs +++ b/asusctl/examples/anime-diag.rs @@ -20,7 +20,7 @@ fn main() { } for c in (0..35).into_iter().step_by(step) { - for i in matrix.get_mut()[c].iter_mut() { + for i in &mut matrix.get_mut()[c] { *i = 50; } } diff --git a/asusctl/examples/anime-grid.rs b/asusctl/examples/anime-grid.rs index a5cb8306..eb115958 100644 --- a/asusctl/examples/anime-grid.rs +++ b/asusctl/examples/anime-grid.rs @@ -17,7 +17,6 @@ fn main() { for (y, row) in tmp.iter_mut().enumerate() { if y % 2 == 0 && i + 1 != row.len() - 1 { i += 1; - dbg!(i); } row[row.len() - i] = 0x22; if i > 5 { diff --git a/asusctl/examples/anime-spinning.rs b/asusctl/examples/anime-spinning.rs index eed3faa5..f4f9c757 100644 --- a/asusctl/examples/anime-spinning.rs +++ b/asusctl/examples/anime-spinning.rs @@ -35,7 +35,7 @@ fn main() -> Result<(), Box> { loop { matrix.angle += 0.05; if matrix.angle > PI * 2.0 { - matrix.angle = 0.0 + matrix.angle = 0.0; } matrix.update(); diff --git a/asusctl/examples/aura-rgb-ball.rs b/asusctl/examples/aura-rgb-ball.rs index bfefc083..c4081b91 100644 --- a/asusctl/examples/aura-rgb-ball.rs +++ b/asusctl/examples/aura-rgb-ball.rs @@ -6,17 +6,17 @@ use rog_aura::{ KeyColourArray, }; use rog_dbus::RogDbusClientBlocking; -use std::collections::LinkedList; +use std::collections::VecDeque; #[derive(Debug, Clone)] struct Ball { position: (f32, f32), direction: (f32, f32), - trail: LinkedList<(f32, f32)>, + trail: VecDeque<(f32, f32)>, } impl Ball { fn new(x: f32, y: f32, trail_len: u32) -> Self { - let mut trail = LinkedList::new(); + let mut trail = VecDeque::new(); for _ in 1..=trail_len { trail.push_back((x, y)); } diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index f080fd94..61bb7846 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -26,7 +26,7 @@ mod aura_cli; mod cli_opts; mod profiles_cli; -fn main() -> Result<(), Box> { +fn main() { let args: Vec = args().skip(1).collect(); let missing_argument_k = gumdrop::Error::missing_argument(Opt::Short('k')); @@ -44,7 +44,7 @@ fn main() -> Result<(), Box> { let (dbus, _) = RogDbusClientBlocking::new() .map_err(|e| { - print_error_help(Box::new(e), None); + print_error_help(&e, None); std::process::exit(3); }) .unwrap(); @@ -54,7 +54,7 @@ fn main() -> Result<(), Box> { .supported() .supported_functions() .map_err(|e| { - print_error_help(Box::new(e), None); + print_error_help(&e, None); std::process::exit(4); }) .unwrap(); @@ -63,17 +63,14 @@ fn main() -> Result<(), Box> { print_versions(); println!(); print_laptop_info(); - return Ok(()); } if let Err(err) = do_parsed(&parsed, &supported, &dbus) { - print_error_help(err, Some(&supported)); + print_error_help(&*err, Some(&supported)); } - - Ok(()) } -fn print_error_help(err: Box, supported: Option<&SupportedFunctions>) { +fn print_error_help(err: &dyn std::error::Error, supported: Option<&SupportedFunctions>) { check_service("asusd"); println!("\nError: {}\n", err); print_versions(); @@ -126,7 +123,7 @@ fn check_service(name: &str) -> bool { fn do_parsed( parsed: &CliStart, supported: &SupportedFunctions, - dbus: &RogDbusClientBlocking, + dbus: &RogDbusClientBlocking<'_>, ) -> Result<(), Box> { match &parsed.command { Some(CliCommand::LedMode(mode)) => handle_led_mode(dbus, &supported.keyboard_led, mode)?, @@ -150,7 +147,7 @@ fn do_parsed( println!("{}", CliStart::usage()); println!(); if let Some(cmdlist) = CliStart::command_list() { - let commands: Vec = cmdlist.lines().map(|s| s.to_string()).collect(); + let commands: Vec = cmdlist.lines().map(|s| s.to_owned()).collect(); for command in commands.iter().filter(|command| { if !matches!( supported.keyboard_led.prod_id, @@ -674,7 +671,9 @@ fn handle_profile( if cmd.list { let res = dbus.proxies().profile().profiles()?; - res.iter().for_each(|p| println!("{:?}", p)); + for p in &res { + println!("{:?}", p); + } } if cmd.profile_get { diff --git a/daemon/src/config.rs b/daemon/src/config.rs index cf48e8c6..676afcc0 100644 --- a/daemon/src/config.rs +++ b/daemon/src/config.rs @@ -42,7 +42,7 @@ impl Config { "Could not deserialise {}.\nWill rename to {}-old and recreate config", CONFIG_PATH, CONFIG_PATH ); - let cfg_old = CONFIG_PATH.to_string() + "-old"; + let cfg_old = CONFIG_PATH.to_owned() + "-old"; std::fs::rename(CONFIG_PATH, cfg_old).unwrap_or_else(|err| { panic!( "Could not rename. Please remove {} then restart service: Error {}", @@ -52,7 +52,7 @@ impl Config { config = Self::new(); } } else { - config = Self::new() + config = Self::new(); } config.write(); config diff --git a/daemon/src/ctrl_anime/config.rs b/daemon/src/ctrl_anime/config.rs index 5050633e..a63a7eac 100644 --- a/daemon/src/ctrl_anime/config.rs +++ b/daemon/src/ctrl_anime/config.rs @@ -86,25 +86,25 @@ impl AnimeConfigCached { anime_type: AnimeType, ) -> Result<(), AnimeError> { let mut sys = Vec::with_capacity(config.system.len()); - for ani in config.system.iter() { + for ani in &config.system { sys.push(ActionData::from_anime_action(anime_type, ani)?); } self.system = sys; let mut boot = Vec::with_capacity(config.boot.len()); - for ani in config.boot.iter() { + for ani in &config.boot { boot.push(ActionData::from_anime_action(anime_type, ani)?); } self.boot = boot; let mut wake = Vec::with_capacity(config.wake.len()); - for ani in config.wake.iter() { + for ani in &config.wake { wake.push(ActionData::from_anime_action(anime_type, ani)?); } self.wake = wake; let mut shutdown = Vec::with_capacity(config.shutdown.len()); - for ani in config.shutdown.iter() { + for ani in &config.shutdown { shutdown.push(ActionData::from_anime_action(anime_type, ani)?); } self.shutdown = shutdown; diff --git a/daemon/src/ctrl_aura/config.rs b/daemon/src/ctrl_aura/config.rs index 12505835..6e9dc2bb 100644 --- a/daemon/src/ctrl_aura/config.rs +++ b/daemon/src/ctrl_aura/config.rs @@ -127,7 +127,7 @@ pub struct AuraConfig { impl Default for AuraConfig { fn default() -> Self { let mut prod_id = AuraDevice::Unknown; - for prod in ASUS_KEYBOARD_DEVICES.iter() { + for prod in &ASUS_KEYBOARD_DEVICES { if HidRaw::new(prod).is_ok() { prod_id = AuraDevice::from(*prod); break; @@ -242,7 +242,7 @@ impl AuraConfig { colour2: *GRADIENT.get(GRADIENT.len() - i).unwrap_or(&GRADIENT[6]), speed: Speed::Med, direction: Direction::Left, - }) + }); } if let Some(m) = config.multizone.as_mut() { m.insert(*n, default); @@ -287,34 +287,31 @@ impl AuraConfig { /// Set the mode data, current mode, and if multizone enabled. /// - /// Multipurpose, will accept AuraEffect with zones and put in the correct store. + /// Multipurpose, will accept `AuraEffect` with zones and put in the correct store. pub fn set_builtin(&mut self, effect: AuraEffect) { self.current_mode = effect.mode; - match effect.zone() { - AuraZone::None => { - self.builtins.insert(*effect.mode(), effect); - self.multizone_on = false; - } - _ => { - if let Some(multi) = self.multizone.as_mut() { - if let Some(fx) = multi.get_mut(effect.mode()) { - for fx in fx.iter_mut() { - if fx.zone == effect.zone { - *fx = effect; - return; - } + if effect.zone() == AuraZone::None { + self.builtins.insert(*effect.mode(), effect); + self.multizone_on = false; + } else { + if let Some(multi) = self.multizone.as_mut() { + if let Some(fx) = multi.get_mut(effect.mode()) { + for fx in fx.iter_mut() { + if fx.zone == effect.zone { + *fx = effect; + return; } - fx.push(effect); - } else { - multi.insert(*effect.mode(), vec![effect]); } + fx.push(effect); } else { - let mut tmp = BTreeMap::new(); - tmp.insert(*effect.mode(), vec![effect]); - self.multizone = Some(tmp); + multi.insert(*effect.mode(), vec![effect]); } - self.multizone_on = true; + } else { + let mut tmp = BTreeMap::new(); + tmp.insert(*effect.mode(), vec![effect]); + self.multizone = Some(tmp); } + self.multizone_on = true; } } diff --git a/daemon/src/ctrl_aura/controller.rs b/daemon/src/ctrl_aura/controller.rs index b3fa5056..5d6bfee7 100644 --- a/daemon/src/ctrl_aura/controller.rs +++ b/daemon/src/ctrl_aura/controller.rs @@ -26,7 +26,7 @@ impl GetSupported for CtrlKbdLed { let per_key_led_mode = laptop.per_key; let mut prod_id = AuraDevice::Unknown; - for prod in ASUS_KEYBOARD_DEVICES.iter() { + for prod in &ASUS_KEYBOARD_DEVICES { if HidRaw::new(prod).is_ok() { prod_id = AuraDevice::from(*prod); break; @@ -72,10 +72,10 @@ impl CtrlKbdLed { pub fn new(supported_modes: LaptopLedData, config: AuraConfig) -> Result { let mut led_prod = None; let mut led_node = None; - for prod in ASUS_KEYBOARD_DEVICES.iter() { + for prod in &ASUS_KEYBOARD_DEVICES { match HidRaw::new(prod) { Ok(node) => { - led_prod = Some(prod.to_string()); + led_prod = Some((*prod).to_owned()); led_node = Some(node); info!("Looked for keyboard controller 0x{prod}: Found"); break; @@ -335,7 +335,7 @@ impl CtrlKbdLed { colour2: *GRADIENT.get(GRADIENT.len() - i).unwrap_or(&GRADIENT[6]), speed: Speed::Med, direction: Direction::Left, - }) + }); } if default.is_empty() { return Err(RogError::AuraEffectNotSupported); @@ -370,7 +370,7 @@ mod tests { // Checking to ensure set_mode errors when unsupported modes are tried let config = AuraConfig::default(); let supported_modes = LaptopLedData { - prod_family: "".into(), + prod_family: String::new(), board_names: vec![], standard: vec![AuraModeNum::Static], multizone: vec![], @@ -432,7 +432,7 @@ mod tests { // Checking to ensure set_mode errors when unsupported modes are tried let config = AuraConfig::default(); let supported_modes = LaptopLedData { - prod_family: "".into(), + prod_family: String::new(), board_names: vec![], standard: vec![AuraModeNum::Static], multizone: vec![], @@ -470,7 +470,7 @@ mod tests { // Checking to ensure set_mode errors when unsupported modes are tried let config = AuraConfig::default(); let supported_modes = LaptopLedData { - prod_family: "".into(), + prod_family: String::new(), board_names: vec![], standard: vec![AuraModeNum::Static], multizone: vec![AuraZone::Key1, AuraZone::Key2], diff --git a/daemon/src/ctrl_aura/trait_impls.rs b/daemon/src/ctrl_aura/trait_impls.rs index 2dbaada6..5219f747 100644 --- a/daemon/src/ctrl_aura/trait_impls.rs +++ b/daemon/src/ctrl_aura/trait_impls.rs @@ -237,7 +237,7 @@ impl CtrlTask for CtrlKbdLedZbus { } async fn create_tasks(&self, _: SignalContext<'static>) -> Result<(), RogError> { - let load_save = |start: bool, mut lock: MutexGuard| { + let load_save = |start: bool, mut lock: MutexGuard<'_, CtrlKbdLed>| { // If waking up if !start { info!("CtrlKbdLedTask reloading brightness and modes"); diff --git a/daemon/src/laptops.rs b/daemon/src/laptops.rs index 745a48d2..2dbab730 100644 --- a/daemon/src/laptops.rs +++ b/daemon/src/laptops.rs @@ -71,7 +71,7 @@ impl LaptopLedData { } impl LedSupportFile { - /// Consumes the LEDModes + /// Consumes the `LEDModes` fn matcher(self, prod_family: &str, board_name: &str) -> Option { for config in self.led_data { if prod_family.contains(&config.prod_family) { diff --git a/rog-control-center/src/tray.rs b/rog-control-center/src/tray.rs index d67d6705..73d785db 100644 --- a/rog-control-center/src/tray.rs +++ b/rog-control-center/src/tray.rs @@ -417,7 +417,7 @@ pub fn init_tray( GfxPower::Off => tray.set_icon("asus_notif_green"), GfxPower::AsusDisabled => tray.set_icon("asus_notif_white"), GfxPower::AsusMuxDiscreet | GfxPower::Active => { - tray.set_icon("asus_notif_red") + tray.set_icon("asus_notif_red"); } GfxPower::Unknown => tray.set_icon("gpu-integrated"), }; diff --git a/rog-profiles/src/lib.rs b/rog-profiles/src/lib.rs index a5ed51b6..f1105782 100644 --- a/rog-profiles/src/lib.rs +++ b/rog-profiles/src/lib.rs @@ -93,7 +93,6 @@ impl From for &str { impl From<&str> for Profile { fn from(profile: &str) -> Profile { match profile.to_ascii_lowercase().trim() { - "balanced" => Profile::Balanced, "performance" => Profile::Performance, "quiet" => Profile::Quiet, _ => Profile::Balanced, @@ -202,7 +201,7 @@ impl FanCurveProfiles { /// Reset the stored (self) and device curve to the defaults of the platform. /// - /// Each platform_profile has a different default and the defualt can be read + /// Each `platform_profile` has a different default and the defualt can be read /// only for the currently active profile. pub fn set_active_curve_to_defaults( &mut self, @@ -296,12 +295,12 @@ impl FanCurveProfiles { FanCurvePU::GPU => &self.balanced.gpu, }, Profile::Performance => match pu { - FanCurvePU::CPU => &self.balanced.cpu, - FanCurvePU::GPU => &self.balanced.gpu, + FanCurvePU::CPU => &self.performance.cpu, + FanCurvePU::GPU => &self.performance.gpu, }, Profile::Quiet => match pu { - FanCurvePU::CPU => &self.balanced.cpu, - FanCurvePU::GPU => &self.balanced.gpu, + FanCurvePU::CPU => &self.quiet.cpu, + FanCurvePU::GPU => &self.quiet.gpu, }, } }