diff --git a/src/io.rs b/src/io.rs index 05bdc3356..70642438b 100644 --- a/src/io.rs +++ b/src/io.rs @@ -1,6 +1,4 @@ use std::collections::HashMap; -use std::fs::File; -use std::io::Read; /// IOLoad represents current system block devices IO statistics #[derive(Debug)] @@ -45,24 +43,30 @@ impl IOLoad { /// /// # Notes /// - /// Current don't support non-unix operating system + /// Currently not supported outside Unix. On those operating systems, this + /// method always returns an empty map. #[cfg(not(unix))] - pub fn snapshot() -> HashMap { + pub fn snapshot() -> HashMap { HashMap::new() } /// Returns the current IO statistics + /// + /// # Notes + /// + /// Currently not supported outside Unix. On those operating systems, this + /// method always returns an empty map. #[cfg(unix)] - pub fn snapshot() -> HashMap { + pub fn snapshot() -> HashMap { let mut result = HashMap::new(); // https://www.kernel.org/doc/Documentation/block/stat.txt if let Ok(dir) = std::fs::read_dir("/sys/block/") { for entry in dir { if let Ok(entry) = entry { let stat = entry.path().join("stat"); - let mut s = String::new(); - if let Err(_) = File::open(stat).and_then(|mut f| f.read_to_string(&mut s)) { - continue; + let s = match std::fs::read_to_string(stat) { + Ok(s) => s, + Err(_) => continue, }; let parts = s .split_whitespace() @@ -71,7 +75,7 @@ impl IOLoad { if parts.len() != 11 { continue; } - let load = IOLoad { + let load = Self { read_io: parts[0], read_merges: parts[1], read_sectors: parts[2], diff --git a/src/net.rs b/src/net.rs index 878c6648b..b103da631 100644 --- a/src/net.rs +++ b/src/net.rs @@ -32,15 +32,21 @@ impl NICLoad { /// /// # Notes /// - /// Current don't support non-unix operating system + /// Currently not supported outside Unix. On those operating systems, this + /// method always returns an empty map. #[cfg(not(unix))] - pub fn snapshot() -> HashMap { + pub fn snapshot() -> HashMap { HashMap::new() } /// Returns the current network interfaces card statistics + /// + /// # Notes + /// + /// Currently not supported outside Unix. On those operating systems, this + /// method always returns an empty map. #[cfg(unix)] - pub fn snapshot() -> HashMap { + pub fn snapshot() -> HashMap { let mut result = HashMap::new(); if let Ok(dir) = std::fs::read_dir("/sys/class/net/") { for entry in dir { @@ -53,7 +59,7 @@ impl NICLoad { .parse() .unwrap_or_default() }; - let load = NICLoad { + let load = Self { rx_bytes: read("rx_bytes"), tx_bytes: read("tx_bytes"), rx_packets: read("rx_packets"), diff --git a/src/windows/processor.rs b/src/windows/processor.rs index 5b99f23eb..6df2dc04c 100644 --- a/src/windows/processor.rs +++ b/src/windows/processor.rs @@ -289,6 +289,7 @@ pub fn get_key_used(p: &mut Processor) -> &mut Option { &mut p.key_used } +/// get_cpu_frequency returns the CPU frequency in MHz pub fn get_cpu_frequency() -> u64 { // TODO: support windows 0