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,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone, Default, Options)]
|
||||
pub struct MultiZone {
|
||||
#[options(help = "print help message")]
|
||||
@@ -194,6 +195,7 @@ pub struct MultiZone {
|
||||
pub colour4: Colour,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone, Default, Options)]
|
||||
pub struct MultiColourSpeed {
|
||||
#[options(help = "print help message")]
|
||||
|
||||
@@ -1184,11 +1184,15 @@ fn print_firmware_attr(attr: &AsusArmouryProxyBlocking) -> Result<(), Box<dyn st
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(clippy::manual_is_multiple_of)]
|
||||
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";
|
||||
if !(cmd.free.len() % 2 == 0) {
|
||||
if odd_len {
|
||||
println!(
|
||||
"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(
|
||||
conn: Option<&Connection>,
|
||||
platform: RogPlatform,
|
||||
@@ -609,20 +610,18 @@ pub async fn start_attributes_zbus(
|
||||
e
|
||||
})?;
|
||||
}
|
||||
} else {
|
||||
if let Some(saved_value) = attr.config.lock().await.armoury_settings.get(&name) {
|
||||
attr.attr
|
||||
.set_current_value(&AttrValue::Integer(*saved_value))
|
||||
.map_err(|e| {
|
||||
error!("Could not set {} value: {e:?}", attr.attr.name());
|
||||
e
|
||||
})?;
|
||||
info!(
|
||||
"Restored armoury setting {} to {:?}",
|
||||
attr.attr.name(),
|
||||
saved_value
|
||||
);
|
||||
}
|
||||
} else if let Some(saved_value) = attr.config.lock().await.armoury_settings.get(&name) {
|
||||
attr.attr
|
||||
.set_current_value(&AttrValue::Integer(*saved_value))
|
||||
.map_err(|e| {
|
||||
error!("Could not set {} value: {e:?}", attr.attr.name());
|
||||
e
|
||||
})?;
|
||||
info!(
|
||||
"Restored armoury setting {} to {:?}",
|
||||
attr.attr.name(),
|
||||
saved_value
|
||||
);
|
||||
}
|
||||
|
||||
registry.push(registry_attr);
|
||||
|
||||
@@ -96,14 +96,17 @@ pub struct AsusDevice {
|
||||
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 {
|
||||
_dbus_connection: Connection,
|
||||
_hid_handles: Arc<Mutex<HashMap<String, Arc<Mutex<HidRaw>>>>>,
|
||||
_hid_handles: HidHandleMap,
|
||||
}
|
||||
|
||||
impl DeviceManager {
|
||||
async fn get_or_create_hid_handle(
|
||||
handles: &Arc<Mutex<HashMap<String, Arc<Mutex<HidRaw>>>>>,
|
||||
handles: &HidHandleMap,
|
||||
endpoint: &Device,
|
||||
) -> Result<(Arc<Mutex<HidRaw>>, String), RogError> {
|
||||
let dev_node = endpoint
|
||||
@@ -124,7 +127,7 @@ impl DeviceManager {
|
||||
async fn init_hid_devices(
|
||||
connection: &Connection,
|
||||
device: Device,
|
||||
handles: Arc<Mutex<HashMap<String, Arc<Mutex<HidRaw>>>>>,
|
||||
handles: HidHandleMap,
|
||||
) -> Result<Vec<AsusDevice>, RogError> {
|
||||
let mut devices = Vec::new();
|
||||
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
|
||||
async fn init_all_hid(
|
||||
connection: &Connection,
|
||||
handles: Arc<Mutex<HashMap<String, Arc<Mutex<HidRaw>>>>>,
|
||||
handles: HidHandleMap,
|
||||
) -> Result<Vec<AsusDevice>, RogError> {
|
||||
// track and ensure we use only one hidraw per prod_id
|
||||
// let mut interfaces = HashSet::new();
|
||||
|
||||
@@ -51,6 +51,7 @@ pub struct CtrlPlatform {
|
||||
}
|
||||
|
||||
impl CtrlPlatform {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
platform: RogPlatform,
|
||||
power: AsusPower,
|
||||
|
||||
Reference in New Issue
Block a user