mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Fix clippy warnings: alias complex types, allow some clippy lints, collapse else-if, avoid is_multiple_of usage
This commit is contained in:
@@ -180,6 +180,7 @@ pub struct TwoColourSpeed {
|
|||||||
pub zone: AuraZone,
|
pub zone: AuraZone,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Debug, Clone, Default, Options)]
|
#[derive(Debug, Clone, Default, Options)]
|
||||||
pub struct MultiZone {
|
pub struct MultiZone {
|
||||||
#[options(help = "print help message")]
|
#[options(help = "print help message")]
|
||||||
@@ -194,6 +195,7 @@ pub struct MultiZone {
|
|||||||
pub colour4: Colour,
|
pub colour4: Colour,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Debug, Clone, Default, Options)]
|
#[derive(Debug, Clone, Default, Options)]
|
||||||
pub struct MultiColourSpeed {
|
pub struct MultiColourSpeed {
|
||||||
#[options(help = "print help message")]
|
#[options(help = "print help message")]
|
||||||
|
|||||||
@@ -1184,11 +1184,15 @@ fn print_firmware_attr(attr: &AsusArmouryProxyBlocking) -> Result<(), Box<dyn st
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::manual_is_multiple_of)]
|
||||||
fn handle_armoury_command(cmd: &ArmouryCommand) -> Result<(), Box<dyn std::error::Error>> {
|
fn handle_armoury_command(cmd: &ArmouryCommand) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
{
|
{
|
||||||
if cmd.free.is_empty() || !cmd.free.len().is_multiple_of(2) || cmd.help {
|
// Avoid using `.is_multiple_of(2)` to satisfy the request. Use modulus check
|
||||||
|
// and simplify the boolean expression.
|
||||||
|
let odd_len = cmd.free.len() % 2 != 0;
|
||||||
|
if cmd.free.is_empty() || odd_len || cmd.help {
|
||||||
const USAGE: &str = "Usage: asusctl platform panel_overdrive 1 nv_dynamic_boost 5";
|
const USAGE: &str = "Usage: asusctl platform panel_overdrive 1 nv_dynamic_boost 5";
|
||||||
if !(cmd.free.len() % 2 == 0) {
|
if odd_len {
|
||||||
println!(
|
println!(
|
||||||
"Incorrect number of args, each attribute label must be paired with a setting:"
|
"Incorrect number of args, each attribute label must be paired with a setting:"
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -524,6 +524,7 @@ impl AsusArmouryAttribute {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub async fn start_attributes_zbus(
|
pub async fn start_attributes_zbus(
|
||||||
conn: Option<&Connection>,
|
conn: Option<&Connection>,
|
||||||
platform: RogPlatform,
|
platform: RogPlatform,
|
||||||
@@ -609,20 +610,18 @@ pub async fn start_attributes_zbus(
|
|||||||
e
|
e
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
} else {
|
} else if let Some(saved_value) = attr.config.lock().await.armoury_settings.get(&name) {
|
||||||
if let Some(saved_value) = attr.config.lock().await.armoury_settings.get(&name) {
|
attr.attr
|
||||||
attr.attr
|
.set_current_value(&AttrValue::Integer(*saved_value))
|
||||||
.set_current_value(&AttrValue::Integer(*saved_value))
|
.map_err(|e| {
|
||||||
.map_err(|e| {
|
error!("Could not set {} value: {e:?}", attr.attr.name());
|
||||||
error!("Could not set {} value: {e:?}", attr.attr.name());
|
e
|
||||||
e
|
})?;
|
||||||
})?;
|
info!(
|
||||||
info!(
|
"Restored armoury setting {} to {:?}",
|
||||||
"Restored armoury setting {} to {:?}",
|
attr.attr.name(),
|
||||||
attr.attr.name(),
|
saved_value
|
||||||
saved_value
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
registry.push(registry_attr);
|
registry.push(registry_attr);
|
||||||
|
|||||||
@@ -96,14 +96,17 @@ pub struct AsusDevice {
|
|||||||
hid_key: Option<String>,
|
hid_key: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Shared alias for the HidRaw handle map used throughout this module.
|
||||||
|
type HidHandleMap = Arc<Mutex<HashMap<String, Arc<Mutex<HidRaw>>>>>;
|
||||||
|
|
||||||
pub struct DeviceManager {
|
pub struct DeviceManager {
|
||||||
_dbus_connection: Connection,
|
_dbus_connection: Connection,
|
||||||
_hid_handles: Arc<Mutex<HashMap<String, Arc<Mutex<HidRaw>>>>>,
|
_hid_handles: HidHandleMap,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DeviceManager {
|
impl DeviceManager {
|
||||||
async fn get_or_create_hid_handle(
|
async fn get_or_create_hid_handle(
|
||||||
handles: &Arc<Mutex<HashMap<String, Arc<Mutex<HidRaw>>>>>,
|
handles: &HidHandleMap,
|
||||||
endpoint: &Device,
|
endpoint: &Device,
|
||||||
) -> Result<(Arc<Mutex<HidRaw>>, String), RogError> {
|
) -> Result<(Arc<Mutex<HidRaw>>, String), RogError> {
|
||||||
let dev_node = endpoint
|
let dev_node = endpoint
|
||||||
@@ -124,7 +127,7 @@ impl DeviceManager {
|
|||||||
async fn init_hid_devices(
|
async fn init_hid_devices(
|
||||||
connection: &Connection,
|
connection: &Connection,
|
||||||
device: Device,
|
device: Device,
|
||||||
handles: Arc<Mutex<HashMap<String, Arc<Mutex<HidRaw>>>>>,
|
handles: HidHandleMap,
|
||||||
) -> Result<Vec<AsusDevice>, RogError> {
|
) -> Result<Vec<AsusDevice>, RogError> {
|
||||||
let mut devices = Vec::new();
|
let mut devices = Vec::new();
|
||||||
if let Some(usb_device) = device.parent_with_subsystem_devtype("usb", "usb_device")? {
|
if let Some(usb_device) = device.parent_with_subsystem_devtype("usb", "usb_device")? {
|
||||||
@@ -212,7 +215,7 @@ impl DeviceManager {
|
|||||||
/// To be called on daemon startup
|
/// To be called on daemon startup
|
||||||
async fn init_all_hid(
|
async fn init_all_hid(
|
||||||
connection: &Connection,
|
connection: &Connection,
|
||||||
handles: Arc<Mutex<HashMap<String, Arc<Mutex<HidRaw>>>>>,
|
handles: HidHandleMap,
|
||||||
) -> Result<Vec<AsusDevice>, RogError> {
|
) -> Result<Vec<AsusDevice>, RogError> {
|
||||||
// track and ensure we use only one hidraw per prod_id
|
// track and ensure we use only one hidraw per prod_id
|
||||||
// let mut interfaces = HashSet::new();
|
// let mut interfaces = HashSet::new();
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ pub struct CtrlPlatform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CtrlPlatform {
|
impl CtrlPlatform {
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
platform: RogPlatform,
|
platform: RogPlatform,
|
||||||
power: AsusPower,
|
power: AsusPower,
|
||||||
|
|||||||
Reference in New Issue
Block a user