From 600d0ae3d984ed0c4de502c48781caae4d3400c0 Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Fri, 30 Sep 2022 15:10:56 +1300 Subject: [PATCH] Clippy run --- .gitlab-ci.yml | 4 +- Cargo.lock | 34 ++++----- Cargo.toml | 4 +- Makefile | 5 ++ asus-notify/src/main.rs | 2 +- asusctl/src/main.rs | 15 ++-- daemon-user/src/daemon.rs | 2 +- daemon-user/src/user_config.rs | 4 +- daemon/src/ctrl_anime/mod.rs | 2 +- daemon/src/ctrl_anime/trait_impls.rs | 8 +-- daemon/src/ctrl_aura/config.rs | 74 ++++++++++++-------- daemon/src/ctrl_aura/controller.rs | 25 +++---- daemon/src/ctrl_aura/trait_impls.rs | 8 +-- daemon/src/ctrl_platform.rs | 57 ++++++--------- daemon/src/ctrl_profiles/trait_impls.rs | 8 +-- daemon/src/daemon.rs | 2 +- rog-anime/src/data.rs | 2 +- rog-anime/src/diagonal.rs | 10 +-- rog-anime/src/image.rs | 2 +- rog-anime/src/usb.rs | 4 +- rog-aura/src/builtin_modes.rs | 10 +-- rog-aura/src/keys.rs | 49 ++++++------- rog-aura/src/layouts/mod.rs | 4 +- rog-aura/src/sequencer/effects.rs | 9 ++- rog-aura/src/usb.rs | 26 +++---- rog-control-center/src/lib.rs | 2 +- rog-control-center/src/main.rs | 2 +- rog-control-center/src/notify.rs | 6 +- rog-control-center/src/page_states.rs | 1 + rog-control-center/src/widgets/aura_power.rs | 8 +-- rog-control-center/src/widgets/rog_bios.rs | 42 ++++++----- rog-platform/src/hid_raw.rs | 2 +- rog-platform/src/keyboard_led.rs | 8 ++- rog-platform/src/lib.rs | 6 +- rog-platform/src/macros.rs | 38 +++++----- rog-platform/src/platform.rs | 10 +-- rog-platform/src/power.rs | 2 +- rog-platform/src/usb_raw.rs | 4 +- rog-profiles/src/lib.rs | 2 +- 39 files changed, 252 insertions(+), 251 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 63a7a0b3..5adc3c65 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,7 +9,9 @@ stages: test: script: - - cargo check #+nightly check --features "clippy" + - rustup component add clippy + - cargo check + - cargo clippy - cargo test build: diff --git a/Cargo.lock b/Cargo.lock index 7dfc045a..e0dcd359 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -86,7 +86,7 @@ dependencies = [ "rog_profiles", "serde_json", "smol", - "zbus 3.1.0", + "zbus 3.2.0", ] [[package]] @@ -584,7 +584,7 @@ dependencies = [ "sysfs-class", "tokio", "toml", - "zbus 3.1.0", + "zbus 3.2.0", "zvariant", ] @@ -601,7 +601,7 @@ dependencies = [ "serde_derive", "serde_json", "smol", - "zbus 3.1.0", + "zbus 3.2.0", "zvariant", "zvariant_derive", ] @@ -1394,7 +1394,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c2bd5667a34b046e66f21ac2c016b1f4b41318423f9282b4e04f755ad947817" dependencies = [ "serde", - "zbus 3.1.0", + "zbus 3.2.0", "zvariant", ] @@ -2032,7 +2032,7 @@ dependencies = [ "smol", "tempfile", "toml", - "zbus 3.1.0", + "zbus 3.2.0", ] [[package]] @@ -2047,7 +2047,7 @@ dependencies = [ "serde", "serde_derive", "sysfs-class", - "zbus 3.1.0", + "zbus 3.2.0", "zvariant", ] @@ -2070,8 +2070,8 @@ dependencies = [ "rog_aura", "rog_platform", "rog_profiles", - "zbus 3.1.0", - "zbus_macros 2.3.2", + "zbus 3.2.0", + "zbus_macros 3.2.0", "zvariant", ] @@ -3148,9 +3148,9 @@ dependencies = [ [[package]] name = "zbus" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d37e0d34b881934b987b72a91fdc1daba9ebc90c1f91b7944c680991c4443fc6" +checksum = "be2db10dd0354816a3615c72deff837f983d5c8ad9a0312727d0f89a5a9e9145" dependencies = [ "async-broadcast", "async-channel", @@ -3180,7 +3180,7 @@ dependencies = [ "tracing", "uds_windows", "winapi", - "zbus_macros 3.1.0", + "zbus_macros 3.2.0", "zbus_names", "zvariant", ] @@ -3200,9 +3200,9 @@ dependencies = [ [[package]] name = "zbus_macros" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba7905f7c665ea41828bd69112902daa131191a85131fef0f60f7cc3bc2fbec4" +checksum = "7d03f1a5fb482cc0d97f3d3de9fe2e942f436a635a5fb6c12c9f03f21eb03075" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -3224,9 +3224,9 @@ dependencies = [ [[package]] name = "zvariant" -version = "3.6.0" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bd68e4e6432ef19df47d7e90e2e72b5e7e3d778e0ae3baddf12b951265cc758" +checksum = "a7b1e052202eb9cc010ad11f556edc81508e1dd08e215188c236c81cd169d83d" dependencies = [ "byteorder", "enumflags2", @@ -3238,9 +3238,9 @@ dependencies = [ [[package]] name = "zvariant_derive" -version = "3.6.0" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08e977eaa3af652f63d479ce50d924254ad76722a6289ec1a1eac3231ca30430" +checksum = "63331f3cf9f98b3bfbc1410ef55ec07f966beea5c0c8797c7003511c0642a2aa" dependencies = [ "proc-macro-crate", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 87fea826..c1fffb65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,8 +11,8 @@ concat-idents = "1.1.3" dirs = "^4.0" smol = "^1.2" -zbus = "^3.1.0" -zbus_macros = "^2.0" +zbus = "^3.2" +zbus_macros = "^3.2" zvariant = "^3.2" zvariant_derive = "^3.2" logind-zbus = { version = "^3.0" } #, default-features = false, features = ["non_blocking"] } diff --git a/Makefile b/Makefile index bc3e0a11..e97a242c 100644 --- a/Makefile +++ b/Makefile @@ -114,5 +114,10 @@ ifeq ($(VENDORED),1) tar pxf vendor_asusctl_$(VERSION).tar.xz endif cargo build $(ARGS) + strip -s ./target/release/$(BIN_C) + strip -s ./target/release/$(BIN_D) + strip -s ./target/release/$(BIN_U) + strip -s ./target/release/$(BIN_N) + strip -s ./target/release/$(BIN_ROG) .PHONY: all clean distclean install uninstall update build diff --git a/asus-notify/src/main.rs b/asus-notify/src/main.rs index bfd64f18..490b0b95 100644 --- a/asus-notify/src/main.rs +++ b/asus-notify/src/main.rs @@ -54,7 +54,7 @@ fn main() -> Result<(), Box> { p.for_each(|e| { if let Ok(out) = e.args() { if let Ok(ref mut lock) = x.try_lock() { - notify!(do_post_sound_notif, lock, &out.on()); + notify!(do_post_sound_notif, lock, out.on()); } } future::ready(()) diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index c3e127b2..4fd9ac82 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -29,23 +29,22 @@ mod profiles_cli; fn main() -> Result<(), Box> { let args: Vec = args().skip(1).collect(); - let parsed: CliStart; let missing_argument_k = gumdrop::Error::missing_argument(Opt::Short('k')); - match CliStart::parse_args_default(&args) { + let parsed = match CliStart::parse_args_default(&args) { Ok(p) => { - parsed = p; + p } Err(err) if err.to_string() == missing_argument_k.to_string() => { - parsed = CliStart { + CliStart { kbd_bright: Some(LedBrightness::new(None)), ..Default::default() - }; + } } Err(err) => { eprintln!("source {}", err); std::process::exit(2); } - } + }; let (dbus, _) = RogDbusClientBlocking::new() .map_err(|e| { @@ -376,7 +375,7 @@ fn handle_anime( } fn verify_brightness(brightness: f32) { - if brightness < 0.0 || brightness > 1.0 { + if !(0.0..=1.0).contains(&brightness) { println!( "Image and global brightness must be between 0.0 and 1.0 (inclusive), was {}", brightness @@ -474,7 +473,7 @@ fn handle_led_power1( } println!("These options are for keyboards of product ID 0x1866 or TUF only"); - return Ok(()); + Ok(()) } fn handle_led_power_1_do_1866( diff --git a/daemon-user/src/daemon.rs b/daemon-user/src/daemon.rs index 964558c2..b2e1f36c 100644 --- a/daemon-user/src/daemon.rs +++ b/daemon-user/src/daemon.rs @@ -86,7 +86,7 @@ fn main() -> Result<(), Box> { .map_err(|e| { println!("{BOARD_NAME}, {e}"); }) - .unwrap_or(KeyLayout::ga401_layout()); + .unwrap_or_else(|_| KeyLayout::ga401_layout()); executor .spawn(async move { diff --git a/daemon-user/src/user_config.rs b/daemon-user/src/user_config.rs index 44ef9ea0..002b9726 100644 --- a/daemon-user/src/user_config.rs +++ b/daemon-user/src/user_config.rs @@ -30,7 +30,7 @@ pub trait ConfigLoadSave { if !path.exists() { create_dir(path.clone())?; } - let name = self.name().clone(); + let name = self.name(); path.push(name + ".cfg"); let mut file = OpenOptions::new() @@ -230,7 +230,7 @@ impl Default for UserAuraConfig { 80, 40, )); - seq.push(key.clone()); + seq.push(key); Self { name: "default".to_string(), diff --git a/daemon/src/ctrl_anime/mod.rs b/daemon/src/ctrl_anime/mod.rs index 96959350..7895ed07 100644 --- a/daemon/src/ctrl_anime/mod.rs +++ b/daemon/src/ctrl_anime/mod.rs @@ -130,7 +130,7 @@ impl CtrlAnime { .ok(); false // Don't exit yet }) - .map(|r| Ok(r)) + .map(Ok) .unwrap_or_else(|| { warn!("rog_anime::run_animation:callback failed"); Err(AnimeError::NoFrames) diff --git a/daemon/src/ctrl_anime/trait_impls.rs b/daemon/src/ctrl_anime/trait_impls.rs index e005e4c0..86f1e59c 100644 --- a/daemon/src/ctrl_anime/trait_impls.rs +++ b/daemon/src/ctrl_anime/trait_impls.rs @@ -123,14 +123,14 @@ impl CtrlAnimeZbus { #[dbus_interface(property)] async fn awake_enabled(&self) -> bool { let lock = self.0.lock().await; - return lock.config.awake_enabled; + lock.config.awake_enabled } /// Get the status of if factory system-status animations are enabled #[dbus_interface(property)] async fn boot_enabled(&self) -> bool { let lock = self.0.lock().await; - return lock.config.boot_anim_enabled; + lock.config.boot_anim_enabled } /// Notify listeners of the status of AniMe LED power and factory system-status animations @@ -152,10 +152,10 @@ impl crate::CtrlTask for CtrlAnimeZbus { |start: bool, lock: MutexGuard, inner: Arc>| { if start { info!("CtrlAnimeTask running sleep animation"); - CtrlAnime::run_thread(inner.clone(), lock.cache.shutdown.clone(), true); + CtrlAnime::run_thread(inner, lock.cache.shutdown.clone(), true); } else { info!("CtrlAnimeTask running wake animation"); - CtrlAnime::run_thread(inner.clone(), lock.cache.wake.clone(), true); + CtrlAnime::run_thread(inner, lock.cache.wake.clone(), true); } }; diff --git a/daemon/src/ctrl_aura/config.rs b/daemon/src/ctrl_aura/config.rs index 50098af8..047ee7af 100644 --- a/daemon/src/ctrl_aura/config.rs +++ b/daemon/src/ctrl_aura/config.rs @@ -27,11 +27,11 @@ impl AuraPowerConfig { match control { AuraPowerConfig::AuraDevTuf(_) => [0, 0, 0], AuraPowerConfig::AuraDev1866(c) => { - let c: Vec = c.iter().map(|v| *v).collect(); + let c: Vec = c.iter().copied().collect(); AuraDev1866::to_bytes(&c) } AuraPowerConfig::AuraDev19b6(c) => { - let c: Vec = c.iter().map(|v| *v).collect(); + let c: Vec = c.iter().copied().collect(); AuraDev19b6::to_bytes(&c) } } @@ -95,19 +95,19 @@ impl From<&AuraPowerConfig> for AuraPowerDev { fn from(config: &AuraPowerConfig) -> Self { match config { AuraPowerConfig::AuraDevTuf(d) => AuraPowerDev { - tuf: d.iter().map(|o| *o).collect(), + tuf: d.iter().copied().collect(), x1866: vec![], x19b6: vec![], }, AuraPowerConfig::AuraDev1866(d) => AuraPowerDev { tuf: vec![], - x1866: d.iter().map(|o| *o).collect(), + x1866: d.iter().copied().collect(), x19b6: vec![], }, AuraPowerConfig::AuraDev19b6(d) => AuraPowerDev { tuf: vec![], x1866: vec![], - x19b6: d.iter().map(|o| *o).collect(), + x19b6: d.iter().copied().collect(), }, } } @@ -128,7 +128,7 @@ impl Default for AuraConfig { fn default() -> Self { let mut prod_id = AuraDevice::Unknown; for prod in ASUS_KEYBOARD_DEVICES.iter() { - if let Ok(_) = HidRaw::new(prod) { + if HidRaw::new(prod).is_ok() { prod_id = AuraDevice::from(*prod); break; } @@ -335,26 +335,34 @@ mod tests { fn set_multizone_4key_config() { let mut config = AuraConfig::default(); - let mut effect = AuraEffect::default(); - effect.colour1 = Colour(0xff, 0x00, 0xff); - effect.zone = AuraZone::Key1; + let effect = AuraEffect { + colour1: Colour(0xff, 0x00, 0xff), + zone: AuraZone::Key1, + ..Default::default() + }; config.set_builtin(effect); assert!(config.multizone.is_some()); - let mut effect = AuraEffect::default(); - effect.colour1 = Colour(0x00, 0xff, 0xff); - effect.zone = AuraZone::Key2; + let effect = AuraEffect { + colour1: Colour(0x00, 0xff, 0xff), + zone: AuraZone::Key2, + ..Default::default() + }; config.set_builtin(effect); - let mut effect = AuraEffect::default(); - effect.colour1 = Colour(0xff, 0xff, 0x00); - effect.zone = AuraZone::Key3; + let effect = AuraEffect { + colour1: Colour(0xff, 0xff, 0x00), + zone: AuraZone::Key3, + ..Default::default() + }; config.set_builtin(effect); - let mut effect = AuraEffect::default(); - effect.colour1 = Colour(0x00, 0xff, 0x00); - effect.zone = AuraZone::Key4; + let effect = AuraEffect { + colour1: Colour(0x00, 0xff, 0x00), + zone: AuraZone::Key4, + ..Default::default() + }; let effect_clone = effect.clone(); config.set_builtin(effect); // This should replace existing @@ -373,25 +381,33 @@ mod tests { fn set_multizone_multimode_config() { let mut config = AuraConfig::default(); - let mut effect = AuraEffect::default(); - effect.zone = AuraZone::Key1; + let effect = AuraEffect { + zone: AuraZone::Key1, + ..Default::default() + }; config.set_builtin(effect); assert!(config.multizone.is_some()); - let mut effect = AuraEffect::default(); - effect.zone = AuraZone::Key2; - effect.mode = AuraModeNum::Breathe; + let effect = AuraEffect { + zone: AuraZone::Key2, + mode: AuraModeNum::Breathe, + ..Default::default() + }; config.set_builtin(effect); - let mut effect = AuraEffect::default(); - effect.zone = AuraZone::Key3; - effect.mode = AuraModeNum::Comet; + let effect = AuraEffect { + zone: AuraZone::Key3, + mode: AuraModeNum::Comet, + ..Default::default() + }; config.set_builtin(effect); - let mut effect = AuraEffect::default(); - effect.zone = AuraZone::Key4; - effect.mode = AuraModeNum::Pulse; + let effect = AuraEffect { + zone: AuraZone::Key4, + mode: AuraModeNum::Pulse, + ..Default::default() + }; config.set_builtin(effect); let res = config.multizone.unwrap(); diff --git a/daemon/src/ctrl_aura/controller.rs b/daemon/src/ctrl_aura/controller.rs index 4ad21fad..8152118e 100644 --- a/daemon/src/ctrl_aura/controller.rs +++ b/daemon/src/ctrl_aura/controller.rs @@ -27,7 +27,7 @@ impl GetSupported for CtrlKbdLed { let mut prod_id = AuraDevice::Unknown; for prod in ASUS_KEYBOARD_DEVICES.iter() { - if let Ok(_) = HidRaw::new(prod) { + if HidRaw::new(prod).is_ok() { prod_id = AuraDevice::from(*prod); break; } @@ -50,7 +50,7 @@ impl GetSupported for CtrlKbdLed { } } -#[derive(Debug, PartialEq, PartialOrd)] +#[derive(Debug, PartialEq, Eq, PartialOrd)] pub enum LEDNode { KbdLed(KeyboardLed), Rog(HidRaw), @@ -121,13 +121,13 @@ impl CtrlKbdLed { pub(super) fn get_brightness(&self) -> Result { self.kd_brightness .get_brightness() - .map_err(|e| RogError::Platform(e)) + .map_err(RogError::Platform) } pub(super) fn set_brightness(&self, brightness: LedBrightness) -> Result<(), RogError> { self.kd_brightness .set_brightness(brightness as u8) - .map_err(|e| RogError::Platform(e)) + .map_err(RogError::Platform) } pub fn next_brightness(&mut self) -> Result<(), RogError> { @@ -176,10 +176,9 @@ impl CtrlKbdLed { /// On success the aura config file is read to refresh cached values, then the effect is /// stored and config written to disk. pub(crate) fn set_effect(&mut self, effect: AuraEffect) -> Result<(), RogError> { - if !self.supported_modes.standard.contains(&effect.mode) { - return Err(RogError::AuraEffectNotSupported); - } else if effect.zone != AuraZone::None - && !self.supported_modes.multizone.contains(&effect.zone) + if !self.supported_modes.standard.contains(&effect.mode) + || effect.zone != AuraZone::None + && !self.supported_modes.multizone.contains(&effect.zone) { return Err(RogError::AuraEffectNotSupported); } @@ -387,9 +386,11 @@ mod tests { config, }; - let mut effect = AuraEffect::default(); - effect.colour1 = Colour(0xff, 0x00, 0xff); - effect.zone = AuraZone::None; + let mut effect = AuraEffect { + colour1: Colour(0xff, 0x00, 0xff), + zone: AuraZone::None, + ..Default::default() + }; // This error comes from write_bytes because we don't have a keyboard node stored assert_eq!( @@ -422,7 +423,7 @@ mod tests { controller.supported_modes.multizone.push(AuraZone::Key2); assert_eq!( controller - .set_effect(effect.clone()) + .set_effect(effect) .unwrap_err() .to_string(), "No supported Aura keyboard" diff --git a/daemon/src/ctrl_aura/trait_impls.rs b/daemon/src/ctrl_aura/trait_impls.rs index 39b24afd..2dbaada6 100644 --- a/daemon/src/ctrl_aura/trait_impls.rs +++ b/daemon/src/ctrl_aura/trait_impls.rs @@ -26,7 +26,7 @@ impl CtrlKbdLedZbus { lock.config.read(); lock.config.brightness = (bright as u32).into(); lock.config.write(); - return Ok(()); + Ok(()) } } @@ -192,19 +192,19 @@ impl CtrlKbdLedZbus { // #[dbus_interface(property)] async fn leds_enabled(&self) -> AuraPowerDev { let ctrl = self.0.lock().await; - return AuraPowerDev::from(&ctrl.config.enabled); + AuraPowerDev::from(&ctrl.config.enabled) } /// Return the current mode data async fn led_mode(&self) -> AuraModeNum { let ctrl = self.0.lock().await; - return ctrl.config.current_mode; + ctrl.config.current_mode } /// Return a list of available modes async fn led_modes(&self) -> BTreeMap { let ctrl = self.0.lock().await; - return ctrl.config.builtins.clone(); + ctrl.config.builtins.clone() } async fn per_key_raw(&self, data: PerKeyRaw) -> zbus::fdo::Result<()> { diff --git a/daemon/src/ctrl_platform.rs b/daemon/src/ctrl_platform.rs index 77063d30..7c601738 100644 --- a/daemon/src/ctrl_platform.rs +++ b/daemon/src/ctrl_platform.rs @@ -202,21 +202,16 @@ impl CtrlPlatform { #[zbus(signal_context)] ctxt: SignalContext<'_>, overdrive: bool, ) { - if self - .platform - .set_panel_od(overdrive) - .map_err(|err| { - warn!("CtrlRogBios: set_panel_overdrive {}", err); - err - }) - .is_ok() - { - if let Some(mut lock) = self.config.try_lock() { - lock.panel_od = overdrive; - lock.write(); + match self.platform.set_panel_od(overdrive) { + Ok(_) => { + if let Some(mut lock) = self.config.try_lock() { + lock.panel_od = overdrive; + lock.write(); + } + Self::notify_panel_od(&ctxt, overdrive).await.ok(); } - Self::notify_panel_od(&ctxt, overdrive).await.ok(); - } + Err(err) => warn!("CtrlRogBios: set_panel_overdrive {}", err), + }; } /// Get the `panel_od` value from platform. Updates the stored value in internal config also. @@ -245,17 +240,12 @@ impl CtrlPlatform { #[zbus(signal_context)] ctxt: SignalContext<'_>, disable: bool, ) { - if self - .platform - .set_dgpu_disable(disable) - .map_err(|err| { - warn!("CtrlRogBios: set_dgpu_disable {}", err); - err - }) - .is_ok() - { - Self::notify_dgpu_disable(&ctxt, disable).await.ok(); - } + match self.platform.set_dgpu_disable(disable) { + Ok(_) => { + Self::notify_dgpu_disable(&ctxt, disable).await.ok(); + } + Err(err) => warn!("CtrlRogBios: set_dgpu_disable {}", err), + }; } fn dgpu_disable(&self) -> bool { @@ -280,17 +270,12 @@ impl CtrlPlatform { #[zbus(signal_context)] ctxt: SignalContext<'_>, enable: bool, ) { - if self - .platform - .set_egpu_enable(enable) - .map_err(|err| { - warn!("CtrlRogBios: set_egpu_enable {}", err); - err - }) - .is_ok() - { - Self::notify_egpu_enable(&ctxt, enable).await.ok(); - } + match self.platform.set_egpu_enable(enable) { + Ok(_) => { + Self::notify_egpu_enable(&ctxt, enable).await.ok(); + } + Err(err) => warn!("CtrlRogBios: set_egpu_enable {}", err), + }; } fn egpu_enable(&self) -> bool { diff --git a/daemon/src/ctrl_profiles/trait_impls.rs b/daemon/src/ctrl_profiles/trait_impls.rs index b8f1f8eb..5d57333f 100644 --- a/daemon/src/ctrl_profiles/trait_impls.rs +++ b/daemon/src/ctrl_profiles/trait_impls.rs @@ -87,7 +87,7 @@ impl ProfileZbus { if let Some(curves) = &ctrl.config.fan_curves { return Ok(curves.get_enabled_curve_profiles().to_vec()); } - return Err(Error::Failed(UNSUPPORTED_MSG.to_string())); + Err(Error::Failed(UNSUPPORTED_MSG.to_string())) } /// Set a profile fan curve enabled status. Will also activate a fan curve if in the @@ -99,7 +99,7 @@ impl ProfileZbus { ) -> zbus::fdo::Result<()> { let mut ctrl = self.0.lock().await; ctrl.config.read(); - return if let Some(curves) = &mut ctrl.config.fan_curves { + if let Some(curves) = &mut ctrl.config.fan_curves { curves.set_profile_curve_enabled(profile, enabled); ctrl.write_profile_curve_to_platform() @@ -110,7 +110,7 @@ impl ProfileZbus { Ok(()) } else { Err(Error::Failed(UNSUPPORTED_MSG.to_string())) - }; + } } /// Get the fan-curve data for the currently active Profile @@ -121,7 +121,7 @@ impl ProfileZbus { let curve = curves.get_fan_curves_for(profile); return Ok(curve.clone()); } - return Err(Error::Failed(UNSUPPORTED_MSG.to_string())); + Err(Error::Failed(UNSUPPORTED_MSG.to_string())) } /// Set the fan curve for the specified profile. diff --git a/daemon/src/daemon.rs b/daemon/src/daemon.rs index b9ced919..2667736c 100644 --- a/daemon/src/daemon.rs +++ b/daemon/src/daemon.rs @@ -151,7 +151,7 @@ where .unwrap_or_else(|err| warn!("Controller error: {}", err)); zbus.add_to_server(connection).await; - task.create_tasks(CtrlKbdLedZbus::signal_context(&connection)?) + task.create_tasks(CtrlKbdLedZbus::signal_context(connection)?) .await .ok(); Ok(()) diff --git a/rog-anime/src/data.rs b/rog-anime/src/data.rs index 57d03577..4f8ecf48 100644 --- a/rog-anime/src/data.rs +++ b/rog-anime/src/data.rs @@ -29,7 +29,7 @@ const USB_PREFIX2: [u8; 7] = [0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x02]; const USB_PREFIX3: [u8; 7] = [0x5e, 0xc0, 0x02, 0xe7, 0x04, 0x73, 0x02]; #[cfg_attr(feature = "dbus", derive(Type))] -#[derive(Debug, PartialEq, Copy, Clone, Deserialize, Serialize)] +#[derive(Debug, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)] pub struct AnimePowerStates { pub brightness: u8, pub enabled: bool, diff --git a/rog-anime/src/diagonal.rs b/rog-anime/src/diagonal.rs index 5a32c34a..10fa27a5 100644 --- a/rog-anime/src/diagonal.rs +++ b/rog-anime/src/diagonal.rs @@ -131,14 +131,14 @@ impl AnimeDiagonal { #[inline] pub fn into_data_buffer(&self, anime_type: AnimeType) -> Result { match anime_type { - AnimeType::GA401 => self.into_ga401_packets(), - AnimeType::GA402 => self.into_ga402_packets(), + AnimeType::GA401 => self.to_ga401_packets(), + AnimeType::GA402 => self.to_ga402_packets(), } } /// Do conversion from the nested Vec in AnimeMatrix to the two required /// packets suitable for sending over USB - fn into_ga401_packets(&self) -> Result { + fn to_ga401_packets(&self) -> Result { let mut buf = vec![0u8; AnimeType::GA401.data_length()]; buf[1..=32].copy_from_slice(&self.get_row(0, 3, 32)); @@ -200,12 +200,12 @@ impl AnimeDiagonal { AnimeDataBuffer::from_vec(crate::AnimeType::GA401, buf) } - fn into_ga402_packets(&self) -> Result { + fn to_ga402_packets(&self) -> Result { let mut buf = vec![0u8; AnimeType::GA402.data_length()]; let mut start_index: usize = 0; fn copy_slice( - buf: &mut Vec, + buf: &mut [u8], anime: &AnimeDiagonal, x: usize, y: usize, diff --git a/rog-anime/src/image.rs b/rog-anime/src/image.rs index 428b4866..376fe298 100644 --- a/rog-anime/src/image.rs +++ b/rog-anime/src/image.rs @@ -88,7 +88,7 @@ impl AnimeImage { width: u32, anime_type: AnimeType, ) -> Result { - if bright < 0.0 || bright > 1.0 { + if !(0.0..=1.0).contains(&bright) { return Err(AnimeError::InvalidBrightness(bright)); } diff --git a/rog-anime/src/usb.rs b/rog-anime/src/usb.rs index 1541af5d..dd0e8003 100644 --- a/rog-anime/src/usb.rs +++ b/rog-anime/src/usb.rs @@ -26,9 +26,7 @@ pub fn get_anime_type() -> Result { let dmi = sysfs_class::DmiId::default(); let board_name = dmi.board_name()?; - if board_name.contains("GA401I") { - return Ok(AnimeType::GA401); - } else if board_name.contains("GA401Q") { + if board_name.contains("GA401I") || board_name.contains("GA401Q") { return Ok(AnimeType::GA401); } else if board_name.contains("GA402R") { return Ok(AnimeType::GA402); diff --git a/rog-aura/src/builtin_modes.rs b/rog-aura/src/builtin_modes.rs index d6e57ce7..037bcf3e 100644 --- a/rog-aura/src/builtin_modes.rs +++ b/rog-aura/src/builtin_modes.rs @@ -12,7 +12,7 @@ use zvariant::Type; use crate::{error::Error, LED_MSG_LEN}; #[cfg_attr(feature = "dbus", derive(Type))] -#[derive(Debug, Copy, Clone, PartialEq, Deserialize, Serialize)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)] pub enum LedBrightness { Off, Low, @@ -33,7 +33,7 @@ impl From for LedBrightness { } #[cfg_attr(feature = "dbus", derive(Type))] -#[derive(Debug, Clone, PartialEq, PartialOrd, Copy, Deserialize, Serialize)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Copy, Deserialize, Serialize)] pub struct Colour(pub u8, pub u8, pub u8); impl Default for Colour { @@ -85,7 +85,7 @@ impl From for [u8; 3] { } #[cfg_attr(feature = "dbus", derive(Type))] -#[derive(Debug, Copy, Clone, PartialEq, Deserialize, Serialize)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)] pub enum Speed { Low = 0xe1, Med = 0xeb, @@ -123,7 +123,7 @@ impl From for u8 { /// /// Enum corresponds to the required integer value #[cfg_attr(feature = "dbus", derive(Type))] -#[derive(Debug, Copy, Clone, PartialEq, Deserialize, Serialize)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)] pub enum Direction { Right, Left, @@ -251,7 +251,7 @@ impl From for AuraModeNum { /// Base effects have no zoning, while multizone is 1-4 #[cfg_attr(feature = "dbus", derive(Type))] -#[derive(Debug, Default, Copy, Clone, PartialEq, Deserialize, Serialize)] +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)] pub enum AuraZone { /// Used if keyboard has no zones, or if setting all #[default] diff --git a/rog-aura/src/keys.rs b/rog-aura/src/keys.rs index 1fbf12c9..b41830f6 100644 --- a/rog-aura/src/keys.rs +++ b/rog-aura/src/keys.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -#[derive(Debug, Default, PartialEq, Copy, Clone, Serialize, Deserialize)] +#[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Serialize, Deserialize)] pub enum Key { VolUp, VolDown, @@ -235,51 +235,44 @@ impl KeyShape { /// A blank is used to space keys out in GUI's and can be used or ignored /// depednign on the per-key effect pub const fn is_blank(&self) -> bool { - match self { + matches!( + self, Self::NormalBlank - | Self::FuncBlank - | Self::ArrowBlank - | Self::ArrowSplitBlank - | Self::ArrowRegularBlank => true, - _ => false, - } + | Self::FuncBlank + | Self::ArrowBlank + | Self::ArrowSplitBlank + | Self::ArrowRegularBlank + ) } /// A spacer is used to space keys out in GUI's, but ignored in per-key effects pub const fn is_spacer(&self) -> bool { - match self { + matches!( + self, Self::FuncSpacer - | Self::NormalSpacer - | Self::ArrowSpacer - | Self::ArrowSplitSpacer - | Self::ArrowRegularSpacer => true, - _ => false, - } + | Self::NormalSpacer + | Self::ArrowSpacer + | Self::ArrowSplitSpacer + | Self::ArrowRegularSpacer + ) } /// All keys with a postfix of some number pub const fn is_group(&self) -> bool { - match self { - Self::LShift3 | Self::RShift3 => true, - Self::Return3 | Self::Space5 | Self::Backspace3 => true, - _ => false, - } + matches!( + self, + Self::LShift3 | Self::RShift3 | Self::Return3 | Self::Space5 | Self::Backspace3 + ) } /// Mostly intended as a helper for signalling when to draw a /// split/compact arrow cluster pub const fn is_arrow_cluster(&self) -> bool { - match self { - Self::Arrow | Self::ArrowBlank | Self::ArrowSpacer => true, - _ => false, - } + matches!(self, Self::Arrow | Self::ArrowBlank | Self::ArrowSpacer) } pub const fn is_arrow_splits(&self) -> bool { - match self { - Self::ArrowSplit | Self::ArrowSplitBlank | Self::ArrowSplitSpacer => true, - _ => false, - } + matches!(self, Self::Arrow | Self::ArrowBlank | Self::ArrowSpacer) } } diff --git a/rog-aura/src/layouts/mod.rs b/rog-aura/src/layouts/mod.rs index 62276669..b168a8ec 100644 --- a/rog-aura/src/layouts/mod.rs +++ b/rog-aura/src/layouts/mod.rs @@ -35,9 +35,9 @@ impl KeyLayout { let mut buf = String::new(); let read_len = file.read_to_string(&mut buf)?; if read_len == 0 { - return Err(Error::Io(std::io::ErrorKind::InvalidData.into())); + Err(Error::Io(std::io::ErrorKind::InvalidData.into())) } else { - return Ok(toml::from_str::(&buf)?); + Ok(toml::from_str::(&buf)?) } } diff --git a/rog-aura/src/sequencer/effects.rs b/rog-aura/src/sequencer/effects.rs index 2bd8c192..a3b83f75 100644 --- a/rog-aura/src/sequencer/effects.rs +++ b/rog-aura/src/sequencer/effects.rs @@ -138,16 +138,15 @@ impl EffectState for Breathe { let speed = 4 - ::from(*speed); - let colour: &mut Colour; if *colour_actual == Colour(0, 0, 0) { *use_colour1 = !*use_colour1; } - if !*use_colour1 { - colour = colour2; + let colour = if !*use_colour1 { + colour2 } else { - colour = colour1; - } + colour1 + }; let r1_scale = colour.0 / speed / 2; let g1_scale = colour.1 / speed / 2; diff --git a/rog-aura/src/usb.rs b/rog-aura/src/usb.rs index 6ee75ade..349032f8 100644 --- a/rog-aura/src/usb.rs +++ b/rog-aura/src/usb.rs @@ -21,7 +21,7 @@ pub const fn aura_brightness_bytes(brightness: u8) -> [u8; 17] { } #[cfg_attr(feature = "dbus", derive(Type))] -#[derive(Clone, Debug, PartialEq, PartialOrd, Serialize, Deserialize, Default)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Serialize, Deserialize, Default)] pub enum AuraDevice { Tuf, X1854, @@ -127,7 +127,7 @@ impl BitOr for AuraDev1866 { type Output = u32; fn bitor(self, rhs: AuraDev1866) -> Self::Output { - return self as u32 | rhs as u32; + self as u32 | rhs as u32 } } @@ -135,7 +135,7 @@ impl BitAnd for AuraDev1866 { type Output = u32; fn bitand(self, rhs: AuraDev1866) -> Self::Output { - return self as u32 & rhs as u32; + self as u32 & rhs as u32 } } @@ -178,14 +178,14 @@ pub enum AuraDev19b6 { SleepKeyb = 1 << 5, ShutdownLogo = 1 << 6, ShutdownKeyb = 1 << 7, - BootBar = 1 << 7 + 2, - AwakeBar = 1 << 7 + 3, - SleepBar = 1 << 7 + 4, - ShutdownBar = 1 << 7 + 5, - BootLid = 1 << 15 + 1, - AwakeLid = 1 << 15 + 2, - SleepLid = 1 << 15 + 3, - ShutdownLid = 1 << 15 + 4, + BootBar = 1 << (7 + 2), + AwakeBar = 1 << (7 + 3), + SleepBar = 1 << (7 + 4), + ShutdownBar = 1 << (7 + 5), + BootLid = 1 << (15 + 1), + AwakeLid = 1 << (15 + 2), + SleepLid = 1 << (15 + 3), + ShutdownLid = 1 << (15 + 4), } impl From for u32 { @@ -216,7 +216,7 @@ impl BitOr for AuraDev19b6 { type Output = u16; fn bitor(self, rhs: AuraDev19b6) -> Self::Output { - return self as u16 | rhs as u16; + self as u16 | rhs as u16 } } @@ -224,7 +224,7 @@ impl BitAnd for AuraDev19b6 { type Output = u16; fn bitand(self, rhs: AuraDev19b6) -> Self::Output { - return self as u16 & rhs as u16; + self as u16 & rhs as u16 } } diff --git a/rog-control-center/src/lib.rs b/rog-control-center/src/lib.rs index b1208fbf..eae7cba5 100644 --- a/rog-control-center/src/lib.rs +++ b/rog-control-center/src/lib.rs @@ -45,7 +45,7 @@ pub fn print_versions() { pub const SHOWING_GUI: u8 = 1; pub const SHOW_GUI: u8 = 2; -#[derive(PartialEq, Clone, Copy)] +#[derive(PartialEq, Eq, Clone, Copy)] pub enum Page { System, AuraEffects, diff --git a/rog-control-center/src/main.rs b/rog-control-center/src/main.rs index c5bf8b46..0e62dde4 100644 --- a/rog-control-center/src/main.rs +++ b/rog-control-center/src/main.rs @@ -72,7 +72,7 @@ fn main() -> Result<(), Box> { .map_err(|e| { println!("{BOARD_NAME}, {e}"); }) - .unwrap_or(KeyLayout::ga401_layout()); + .unwrap_or_else(|_| KeyLayout::ga401_layout()); // Cheap method to alert to notifications rather than spinning a thread for each // This is quite different when done in a retained mode app diff --git a/rog-control-center/src/notify.rs b/rog-control-center/src/notify.rs index 344fee67..68bf5fe9 100644 --- a/rog-control-center/src/notify.rs +++ b/rog-control-center/src/notify.rs @@ -114,7 +114,7 @@ pub fn start_notifications( }) .detach(); - let bios_notified1 = bios_notified.clone(); + let bios_notified1 = bios_notified; executor .spawn(async move { let conn = zbus::Connection::system().await.unwrap(); @@ -181,9 +181,9 @@ pub fn start_notifications( .detach(); // LED notif - let last_notif = last_notification.clone(); + let last_notif = last_notification; let aura_notif = aura_notified.clone(); - let notifs_enabled1 = notifs_enabled.clone(); + let notifs_enabled1 = notifs_enabled; executor .spawn(async move { let conn = zbus::Connection::system().await.unwrap(); diff --git a/rog-control-center/src/page_states.rs b/rog-control-center/src/page_states.rs index 82d19706..c2df68d0 100644 --- a/rog-control-center/src/page_states.rs +++ b/rog-control-center/src/page_states.rs @@ -262,6 +262,7 @@ pub struct PageDataStates { pub error: Option, } +#[allow(clippy::too_many_arguments)] impl PageDataStates { pub fn new( keyboard_layout: KeyLayout, diff --git a/rog-control-center/src/widgets/aura_power.rs b/rog-control-center/src/widgets/aura_power.rs index 5fc42d54..bac47e1e 100644 --- a/rog-control-center/src/widgets/aura_power.rs +++ b/rog-control-center/src/widgets/aura_power.rs @@ -73,10 +73,10 @@ fn aura_power1( if ui.toggle_value(&mut keyboard, "Keyboard").changed() { changed = true; } - if !supported.keyboard_led.multizone_led_mode.is_empty() { - if ui.toggle_value(&mut lightbar, "Lightbar").changed() { - changed = true; - } + if !supported.keyboard_led.multizone_led_mode.is_empty() + && ui.toggle_value(&mut lightbar, "Lightbar").changed() + { + changed = true; } }); ui.horizontal_wrapped(|ui| { diff --git a/rog-control-center/src/widgets/rog_bios.rs b/rog-control-center/src/widgets/rog_bios.rs index 7754c065..fdc6dec1 100644 --- a/rog-control-center/src/widgets/rog_bios.rs +++ b/rog-control-center/src/widgets/rog_bios.rs @@ -54,40 +54,38 @@ pub fn rog_bios_group( .ok(); } - if supported.rog_bios_ctrl.post_sound { - if ui + if supported.rog_bios_ctrl.post_sound + && ui .add(egui::Checkbox::new( &mut states.bios.post_sound, "POST sound", )) .changed() - { - dbus.proxies() - .rog_bios() - .set_post_boot_sound(states.bios.post_sound) - .map_err(|err| { - states.error = Some(err.to_string()); - }) - .ok(); - } + { + dbus.proxies() + .rog_bios() + .set_post_boot_sound(states.bios.post_sound) + .map_err(|err| { + states.error = Some(err.to_string()); + }) + .ok(); } - if supported.rog_bios_ctrl.post_sound { - if ui + if supported.rog_bios_ctrl.post_sound + && ui .add(egui::Checkbox::new( &mut states.bios.panel_overdrive, "Panel overdrive", )) .changed() - { - dbus.proxies() - .rog_bios() - .set_panel_od(states.bios.panel_overdrive) - .map_err(|err| { - states.error = Some(err.to_string()); - }) - .ok(); - } + { + dbus.proxies() + .rog_bios() + .set_panel_od(states.bios.panel_overdrive) + .map_err(|err| { + states.error = Some(err.to_string()); + }) + .ok(); } if supported.rog_bios_ctrl.gpu_mux { diff --git a/rog-platform/src/hid_raw.rs b/rog-platform/src/hid_raw.rs index a793b852..3d7d9f7f 100644 --- a/rog-platform/src/hid_raw.rs +++ b/rog-platform/src/hid_raw.rs @@ -4,7 +4,7 @@ use log::{info, warn}; use crate::error::{PlatformError, Result}; -#[derive(Debug, PartialEq, PartialOrd, Clone)] +#[derive(Debug, PartialEq, Eq, PartialOrd, Clone)] pub struct HidRaw(PathBuf); impl HidRaw { diff --git a/rog-platform/src/keyboard_led.rs b/rog-platform/src/keyboard_led.rs index c911e0cb..d5bba6a0 100644 --- a/rog-platform/src/keyboard_led.rs +++ b/rog-platform/src/keyboard_led.rs @@ -8,7 +8,7 @@ use crate::{ has_attr, set_attr_u8_array, to_device, }; -#[derive(Debug, Default, PartialEq, PartialOrd, Clone)] +#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Clone)] pub struct KeyboardLed { path: PathBuf, } @@ -32,10 +32,12 @@ impl KeyboardLed { PlatformError::Udev("match_subsystem failed".into(), err) })?; - for device in enumerator.scan_devices().map_err(|err| { + if let Some(device) = (enumerator.scan_devices().map_err(|err| { warn!("{}", err); PlatformError::Udev("scan_devices failed".into(), err) - })? { + })?) + .next() + { info!("Found keyboard LED controls at {:?}", device.sysname()); return Ok(Self { path: device.syspath().to_owned(), diff --git a/rog-platform/src/lib.rs b/rog-platform/src/lib.rs index 8c118860..1a120207 100644 --- a/rog-platform/src/lib.rs +++ b/rog-platform/src/lib.rs @@ -51,7 +51,7 @@ pub fn write_attr_bool(device: &mut Device, attr: &str, value: bool) -> Result<( pub fn read_attr_u8(device: &Device, attr_name: &str) -> Result { if let Some(value) = device.attribute_value(attr_name) { let tmp = value.to_string_lossy(); - return Ok(tmp.parse::().map_err(|_| PlatformError::ParseNum)?); + return tmp.parse::().map_err(|_| PlatformError::ParseNum); } Err(PlatformError::AttrNotFound(attr_name.to_string())) } @@ -67,7 +67,7 @@ pub fn read_attr_u8_array(device: &Device, attr_name: &str) -> Result> { let tmp = value.to_string_lossy(); let tmp = tmp .split(' ') - .map(|v| u8::from_str_radix(v, 10).unwrap_or(0)) + .map(|v| v.parse::().unwrap_or(0)) .collect(); return Ok(tmp); } @@ -94,7 +94,7 @@ mod tests { let tmp: Vec = tmp .split(' ') - .map(|v| u8::from_str_radix(v, 10).unwrap_or(0)) + .map(|v| v.parse::().unwrap_or(0)) .collect(); assert_eq!(tmp, &[1, 2, 3, 4, 5]); } diff --git a/rog-platform/src/macros.rs b/rog-platform/src/macros.rs index 0989b290..675430c6 100644 --- a/rog-platform/src/macros.rs +++ b/rog-platform/src/macros.rs @@ -5,7 +5,7 @@ macro_rules! has_attr { $(#[$doc_comment])* pub fn fn_name(&self) -> bool { match to_device(&self.$item) { - Ok(p) => crate::has_attr(&p, $attr_name), + Ok(p) => $crate::has_attr(&p, $attr_name), Err(_) => false, } } @@ -45,7 +45,7 @@ macro_rules! get_attr_bool { concat_idents::concat_idents!(fn_name = get_, $attr_name { $(#[$doc_comment])* pub fn fn_name(&self) -> Result { - crate::read_attr_bool(&to_device(&self.$item)?, $attr_name) + $crate::read_attr_bool(&to_device(&self.$item)?, $attr_name) } }); }; @@ -57,7 +57,7 @@ macro_rules! set_attr_bool { concat_idents::concat_idents!(fn_name = set_, $attr_name { $(#[$doc_comment])* pub fn fn_name(&self, value: bool) -> Result<()> { - crate::write_attr_bool(&mut to_device(&self.$item)?, $attr_name, value) + $crate::write_attr_bool(&mut to_device(&self.$item)?, $attr_name, value) } }); }; @@ -66,10 +66,10 @@ macro_rules! set_attr_bool { #[macro_export] macro_rules! attr_bool { ($attr_name:literal, $item:ident) => { - crate::has_attr!($attr_name $item); - crate::get_attr_bool!( $attr_name $item); - crate::set_attr_bool!($attr_name $item); - crate::watch_attr!($attr_name $item); + $crate::has_attr!($attr_name $item); + $crate::get_attr_bool!( $attr_name $item); + $crate::set_attr_bool!($attr_name $item); + $crate::watch_attr!($attr_name $item); }; } @@ -79,7 +79,7 @@ macro_rules! get_attr_u8 { concat_idents::concat_idents!(fn_name = get_, $attr_name { $(#[$doc_comment])* pub fn fn_name(&self) -> Result { - crate::read_attr_u8(&to_device(&self.$item)?, $attr_name) + $crate::read_attr_u8(&to_device(&self.$item)?, $attr_name) } }); }; @@ -91,7 +91,7 @@ macro_rules! set_attr_u8 { concat_idents::concat_idents!(fn_name = set_, $attr_name { $(#[$doc_comment])* pub fn fn_name(&self, value: u8) -> Result<()> { - crate::write_attr_u8(&mut to_device(&self.$item)?, $attr_name, value) + $crate::write_attr_u8(&mut to_device(&self.$item)?, $attr_name, value) } }); }; @@ -100,10 +100,10 @@ macro_rules! set_attr_u8 { #[macro_export] macro_rules! attr_u8 { ($attr_name:literal, $item:ident) => { - crate::has_attr!($attr_name $item); - crate::get_attr_u8!($attr_name $item); - crate::set_attr_u8!($attr_name $item); - crate::watch_attr!($attr_name $item); + $crate::has_attr!($attr_name $item); + $crate::get_attr_u8!($attr_name $item); + $crate::set_attr_u8!($attr_name $item); + $crate::watch_attr!($attr_name $item); }; } @@ -113,7 +113,7 @@ macro_rules! get_attr_u8_array { concat_idents::concat_idents!(fn_name = get_, $attr_name { $(#[$doc_comment])* pub fn fn_name(&self) -> Result> { - crate::read_attr_u8_array(&to_device(&self.$item)?, $attr_name) + $crate::read_attr_u8_array(&to_device(&self.$item)?, $attr_name) } }); }; @@ -125,7 +125,7 @@ macro_rules! set_attr_u8_array { concat_idents::concat_idents!(fn_name = set_, $attr_name { $(#[$doc_comment])* pub fn fn_name(&self, values: &[u8]) -> Result<()> { - crate::write_attr_u8_array(&mut to_device(&self.$item)?, $attr_name, values) + $crate::write_attr_u8_array(&mut to_device(&self.$item)?, $attr_name, values) } }); }; @@ -134,9 +134,9 @@ macro_rules! set_attr_u8_array { #[macro_export] macro_rules! attr_u8_array { ($attr_name:literal, $item:ident) => { - crate::has_attr!($attr_name $item); - crate::get_attr_u8_array!($attr_name $item); - crate::set_attr_u8_array!($attr_name $item); - crate::watch_attr!($attr_name $item); + $crate::has_attr!($attr_name $item); + $crate::get_attr_u8_array!($attr_name $item); + $crate::set_attr_u8_array!($attr_name $item); + $crate::watch_attr!($attr_name $item); }; } diff --git a/rog-platform/src/platform.rs b/rog-platform/src/platform.rs index 8658a28b..a0715c42 100644 --- a/rog-platform/src/platform.rs +++ b/rog-platform/src/platform.rs @@ -17,7 +17,7 @@ use crate::{ /// - gpu_mux /// - keyboard_mode, set keyboard RGB mode and speed /// - keyboard_state, set keyboard power states -#[derive(Debug, PartialEq, PartialOrd, Clone)] +#[derive(Debug, PartialEq, Eq, PartialOrd, Clone)] pub struct AsusPlatform { path: PathBuf, pp_path: PathBuf, @@ -38,10 +38,12 @@ impl AsusPlatform { PlatformError::Udev("match_subsystem failed".into(), err) })?; - for device in enumerator.scan_devices().map_err(|err| { + if let Some(device) = (enumerator.scan_devices().map_err(|err| { warn!("{}", err); PlatformError::Udev("scan_devices failed".into(), err) - })? { + })?) + .next() + { info!("Found platform support at {:?}", device.sysname()); return Ok(Self { path: device.syspath().to_owned(), @@ -63,7 +65,7 @@ impl AsusPlatform { attr_u8!("platform_profile", pp_path); } -#[derive(Serialize, Deserialize, Type, Debug, PartialEq, Clone, Copy)] +#[derive(Serialize, Deserialize, Type, Debug, PartialEq, Eq, Clone, Copy)] pub enum GpuMode { Discrete, Optimus, diff --git a/rog-platform/src/power.rs b/rog-platform/src/power.rs index ce25b525..a7979166 100644 --- a/rog-platform/src/power.rs +++ b/rog-platform/src/power.rs @@ -15,7 +15,7 @@ use crate::{ /// - gpu_mux /// - keyboard_mode, set keyboard RGB mode and speed /// - keyboard_state, set keyboard power states -#[derive(Debug, PartialEq, PartialOrd, Clone)] +#[derive(Debug, PartialEq, Eq, PartialOrd, Clone)] pub struct AsusPower { mains: PathBuf, battery: PathBuf, diff --git a/rog-platform/src/usb_raw.rs b/rog-platform/src/usb_raw.rs index 34b32097..3e1fa053 100644 --- a/rog-platform/src/usb_raw.rs +++ b/rog-platform/src/usb_raw.rs @@ -3,7 +3,7 @@ use std::time::Duration; use crate::error::{PlatformError, Result}; -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub struct USBRaw(DeviceHandle); impl USBRaw { @@ -43,6 +43,6 @@ impl USBRaw { message, Duration::from_millis(200), ) - .map_err(|e| PlatformError::USB(e)) + .map_err(PlatformError::USB) } } diff --git a/rog-profiles/src/lib.rs b/rog-profiles/src/lib.rs index be9054e0..23df403c 100644 --- a/rog-profiles/src/lib.rs +++ b/rog-profiles/src/lib.rs @@ -114,7 +114,7 @@ impl std::str::FromStr for Profile { } #[cfg_attr(feature = "dbus", derive(Type))] -#[derive(Deserialize, Serialize, Debug, PartialEq, Clone, Copy)] +#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone, Copy)] pub enum FanCurvePU { CPU, GPU,