From a11f6e88f8ad03873c6c559fcb9b53e46c1d3d11 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 22 Aug 2019 09:28:44 +0200 Subject: [PATCH] [clippy] sys: simplifications and optimizations Signed-off-by: Wolfgang Bumiller --- proxmox-sys/src/linux/magic.rs | 1 + proxmox-sys/src/linux/procfs.rs | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/proxmox-sys/src/linux/magic.rs b/proxmox-sys/src/linux/magic.rs index e229b0b5..908a8c76 100644 --- a/proxmox-sys/src/linux/magic.rs +++ b/proxmox-sys/src/linux/magic.rs @@ -3,6 +3,7 @@ // from /usr/include/linux/magic.h // and from casync util.h #[rustfmt::skip] +#[allow(clippy::unreadable_literal)] mod consts { pub const BINFMTFS_MAGIC : i64 = 0x42494e4d; pub const CGROUP2_SUPER_MAGIC : i64 = 0x63677270; diff --git a/proxmox-sys/src/linux/procfs.rs b/proxmox-sys/src/linux/procfs.rs index 48601da2..39e6f4b5 100644 --- a/proxmox-sys/src/linux/procfs.rs +++ b/proxmox-sys/src/linux/procfs.rs @@ -73,7 +73,7 @@ pub fn read_proc_starttime(pid: libc::pid_t) -> Result { pub fn check_process_running(pid: libc::pid_t) -> Option { if let Ok(info) = read_proc_pid_stat(pid) { - if info.status != 'Z' as u8 { + if info.status != b'Z' { return Some(info); } } @@ -95,7 +95,7 @@ pub fn read_proc_uptime() -> Result<(f64, f64), Error> { let mut values = line.split_whitespace().map(|v| v.parse::()); match (values.next(), values.next()) { - (Some(Ok(up)), Some(Ok(idle))) => return Ok((up, idle)), + (Some(Ok(up)), Some(Ok(idle))) => Ok((up, idle)), _ => bail!("Error while parsing '{}'", path), } } @@ -195,7 +195,7 @@ pub fn read_cpuinfo() -> Result { if content.is_empty() { continue; } - let mut content_iter = content.split(":"); + let mut content_iter = content.split(':'); match (content_iter.next(), content_iter.next()) { (Some(key), Some(value)) => match key.trim_end() { "processor" => cpuinfo.cpus += 1, @@ -254,7 +254,7 @@ pub fn read_proc_net_dev() -> Result, Error> { for line in BufReader::new(&file).lines().skip(2) { let content = line?; let mut iter = content.split_whitespace(); - match (iter.next(), iter.next(), iter.skip(7).next()) { + match (iter.next(), iter.next(), iter.nth(7)) { (Some(device), Some(receive), Some(send)) => { result.push(ProcFsNetDev { device: device[..device.len() - 1].to_string(), @@ -316,7 +316,7 @@ pub fn read_proc_net_route() -> Result, Error> { let mut next = || { iter.next() - .ok_or(format_err!("Error while parsing '{}'", path)) + .ok_or_else(|| format_err!("Error while parsing '{}'", path)) }; let (iface, dest, gateway) = (next()?, next()?, next()?);