From 76189efee4f93a7a2e8a27249ca6c0db57da7c1a Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Mon, 23 Dec 2019 00:57:16 -0500 Subject: [PATCH] Fix some more clippy hints. --- src/app/data_collection/processes.rs | 45 +++++++++++++------------- src/app/data_collection/temperature.rs | 26 ++++++--------- 2 files changed, 31 insertions(+), 40 deletions(-) diff --git a/src/app/data_collection/processes.rs b/src/app/data_collection/processes.rs index 982ebfaa..c3154b0b 100644 --- a/src/app/data_collection/processes.rs +++ b/src/app/data_collection/processes.rs @@ -1,3 +1,4 @@ +use std::cmp::Ordering; use std::{collections::HashMap, process::Command, time::Instant}; use sysinfo::{ProcessExt, System, SystemExt}; @@ -79,20 +80,25 @@ fn vangelis_cpu_usage_calculation(prev_idle: &mut f64, prev_non_idle: &mut f64) } fn get_ordering(a_val: T, b_val: T, reverse_order: bool) -> std::cmp::Ordering { - if a_val > b_val { - if reverse_order { - std::cmp::Ordering::Less - } else { - std::cmp::Ordering::Greater - } - } else if a_val < b_val { - if reverse_order { - std::cmp::Ordering::Greater - } else { - std::cmp::Ordering::Less - } - } else { - std::cmp::Ordering::Equal + match a_val.partial_cmp(&b_val) { + Some(x) => match x { + Ordering::Greater => { + if reverse_order { + std::cmp::Ordering::Less + } else { + std::cmp::Ordering::Greater + } + } + Ordering::Less => { + if reverse_order { + std::cmp::Ordering::Greater + } else { + std::cmp::Ordering::Less + } + } + Ordering::Equal => Ordering::Equal, + }, + None => Ordering::Equal, // I don't really like this but I think it's fine... } } @@ -184,8 +190,8 @@ pub async fn get_sorted_processes_list( } } } - } else if cfg!(target_os = "windows") { - // Windows + } else { + // Windows et al. let process_hashmap = sys.get_process_list(); for process_val in process_hashmap.values() { @@ -197,13 +203,6 @@ pub async fn get_sorted_processes_list( cpu_usage_percent: f64::from(process_val.cpu_usage()), }); } - } else if cfg!(target_os = "macos") { - // TODO: macOS - debug!("Mac"); - } else { - // TODO: Others? - debug!("Else"); - // Solaris: https://stackoverflow.com/a/4453581 } Ok(process_vector) diff --git a/src/app/data_collection/temperature.rs b/src/app/data_collection/temperature.rs index 7a455aff..2e0bf85e 100644 --- a/src/app/data_collection/temperature.rs +++ b/src/app/data_collection/temperature.rs @@ -1,5 +1,6 @@ use futures::StreamExt; use heim::units::thermodynamic_temperature; +use std::cmp::Ordering; use sysinfo::{ComponentExt, System, SystemExt}; #[derive(Clone)] @@ -55,25 +56,16 @@ pub async fn get_temperature_data(sys: &System, temp_type: &TemperatureType) -> // By default, sort temperature, then by alphabetically! Allow for configuring this... // Note we sort in reverse here; we want greater temps to be higher priority. - temperature_vec.sort_by(|a, b| { - if a.temperature > b.temperature { - std::cmp::Ordering::Less - } else if a.temperature < b.temperature { - std::cmp::Ordering::Greater - } else { - std::cmp::Ordering::Equal - } + temperature_vec.sort_by(|a, b| match a.temperature.partial_cmp(&b.temperature) { + Some(x) => match x { + Ordering::Less => Ordering::Greater, + Ordering::Greater => Ordering::Less, + Ordering::Equal => Ordering::Equal, + }, + None => Ordering::Equal, }); - temperature_vec.sort_by(|a, b| { - if a.component_name > b.component_name { - std::cmp::Ordering::Greater - } else if a.component_name < b.component_name { - std::cmp::Ordering::Less - } else { - std::cmp::Ordering::Equal - } - }); + temperature_vec.sort_by(|a, b| a.component_name.partial_cmp(&b.component_name).unwrap_or(Ordering::Equal)); Ok(temperature_vec) }