mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Clippy run
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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<u8> {
|
||||
if let Some(value) = device.attribute_value(attr_name) {
|
||||
let tmp = value.to_string_lossy();
|
||||
return Ok(tmp.parse::<u8>().map_err(|_| PlatformError::ParseNum)?);
|
||||
return tmp.parse::<u8>().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<Vec<u8>> {
|
||||
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::<u8>().unwrap_or(0))
|
||||
.collect();
|
||||
return Ok(tmp);
|
||||
}
|
||||
@@ -94,7 +94,7 @@ mod tests {
|
||||
|
||||
let tmp: Vec<u8> = tmp
|
||||
.split(' ')
|
||||
.map(|v| u8::from_str_radix(v, 10).unwrap_or(0))
|
||||
.map(|v| v.parse::<u8>().unwrap_or(0))
|
||||
.collect();
|
||||
assert_eq!(tmp, &[1, 2, 3, 4, 5]);
|
||||
}
|
||||
|
||||
@@ -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<bool> {
|
||||
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<u8> {
|
||||
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<Vec<u8>> {
|
||||
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);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::time::Duration;
|
||||
|
||||
use crate::error::{PlatformError, Result};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct USBRaw(DeviceHandle<rusb::GlobalContext>);
|
||||
|
||||
impl USBRaw {
|
||||
@@ -43,6 +43,6 @@ impl USBRaw {
|
||||
message,
|
||||
Duration::from_millis(200),
|
||||
)
|
||||
.map_err(|e| PlatformError::USB(e))
|
||||
.map_err(PlatformError::USB)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user