Fix some more clippy hints.

This commit is contained in:
Clement Tsang 2019-12-23 00:57:16 -05:00
parent 4b336a7df2
commit 76189efee4
2 changed files with 31 additions and 40 deletions

View file

@ -1,3 +1,4 @@
use std::cmp::Ordering;
use std::{collections::HashMap, process::Command, time::Instant}; use std::{collections::HashMap, process::Command, time::Instant};
use sysinfo::{ProcessExt, System, SystemExt}; 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<T: std::cmp::PartialOrd>(a_val: T, b_val: T, reverse_order: bool) -> std::cmp::Ordering { fn get_ordering<T: std::cmp::PartialOrd>(a_val: T, b_val: T, reverse_order: bool) -> std::cmp::Ordering {
if a_val > b_val { match a_val.partial_cmp(&b_val) {
if reverse_order { Some(x) => match x {
std::cmp::Ordering::Less Ordering::Greater => {
} else { if reverse_order {
std::cmp::Ordering::Greater std::cmp::Ordering::Less
} } else {
} else if a_val < b_val { std::cmp::Ordering::Greater
if reverse_order { }
std::cmp::Ordering::Greater }
} else { Ordering::Less => {
std::cmp::Ordering::Less if reverse_order {
} std::cmp::Ordering::Greater
} else { } else {
std::cmp::Ordering::Equal 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") { } else {
// Windows // Windows et al.
let process_hashmap = sys.get_process_list(); let process_hashmap = sys.get_process_list();
for process_val in process_hashmap.values() { 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()), 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) Ok(process_vector)

View file

@ -1,5 +1,6 @@
use futures::StreamExt; use futures::StreamExt;
use heim::units::thermodynamic_temperature; use heim::units::thermodynamic_temperature;
use std::cmp::Ordering;
use sysinfo::{ComponentExt, System, SystemExt}; use sysinfo::{ComponentExt, System, SystemExt};
#[derive(Clone)] #[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... // 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. // Note we sort in reverse here; we want greater temps to be higher priority.
temperature_vec.sort_by(|a, b| { temperature_vec.sort_by(|a, b| match a.temperature.partial_cmp(&b.temperature) {
if a.temperature > b.temperature { Some(x) => match x {
std::cmp::Ordering::Less Ordering::Less => Ordering::Greater,
} else if a.temperature < b.temperature { Ordering::Greater => Ordering::Less,
std::cmp::Ordering::Greater Ordering::Equal => Ordering::Equal,
} else { },
std::cmp::Ordering::Equal None => Ordering::Equal,
}
}); });
temperature_vec.sort_by(|a, b| { temperature_vec.sort_by(|a, b| a.component_name.partial_cmp(&b.component_name).unwrap_or(Ordering::Equal));
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
}
});
Ok(temperature_vec) Ok(temperature_vec)
} }