From 4974ae08867f94506dce7096aabd9d739a1a7bf5 Mon Sep 17 00:00:00 2001
From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com>
Date: Sun, 22 Dec 2019 17:37:07 -0500
Subject: [PATCH] Some simple fixes to abide by clippy
---
README.md | 4 ++--
src/app/data_collection/disks.rs | 10 +---------
src/app/process_killer.rs | 4 +---
src/canvas.rs | 4 ++--
src/data_conversion.rs | 16 ++++++++--------
src/main.rs | 2 +-
src/utils/error.rs | 2 +-
7 files changed, 16 insertions(+), 26 deletions(-)
diff --git a/README.md b/README.md
index 0d2af447..752435fa 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,7 @@ macOS support will hopefully come soonTM.
## Usage
-Note that all options and keybinds on GitHub may reflect the current development build, and not that of the current releases. For now, refer to the [crate](https://crates.io/crates/bottom) README for documentation as of time of release.
+Note that all options and keybindings on GitHub may reflect the current development build, and not that of the current releases. For now, refer to the [crate](https://crates.io/crates/bottom) README for documentation as of time of release.
### Command line options
@@ -44,7 +44,7 @@ Note that all options and keybinds on GitHub may reflect the current development
- `-r `, `--rate ` will set the refresh rate in _milliseconds_. Lowest it can go is 250ms, the highest it can go is 2128 - 1. Defaults to 1000ms, and lower values may take more resources due to more frequent polling of data, and may be less accurate in some circumstances.
-### Keybinds
+### Keybindings
#### General
diff --git a/src/app/data_collection/disks.rs b/src/app/data_collection/disks.rs
index f6ce7906..1bacc54e 100644
--- a/src/app/data_collection/disks.rs
+++ b/src/app/data_collection/disks.rs
@@ -87,15 +87,7 @@ pub async fn get_disk_usage_list() -> crate::utils::error::Result>
}
}
- vec_disks.sort_by(|a, b| {
- if a.name < b.name {
- std::cmp::Ordering::Less
- } else if a.name > b.name {
- std::cmp::Ordering::Greater
- } else {
- std::cmp::Ordering::Equal
- }
- });
+ vec_disks.sort_by(|a, b| a.name.cmp(&b.name));
Ok(vec_disks)
}
diff --git a/src/app/process_killer.rs b/src/app/process_killer.rs
index 46396a78..4dc267be 100644
--- a/src/app/process_killer.rs
+++ b/src/app/process_killer.rs
@@ -3,8 +3,6 @@ use std::process::Command;
// Copied from SO: https://stackoverflow.com/a/55231715
#[cfg(target_os = "windows")]
-use std::ptr::null_mut;
-#[cfg(target_os = "windows")]
use winapi::{
shared::{minwindef::DWORD, ntdef::HANDLE},
um::{
@@ -20,7 +18,7 @@ struct Process(HANDLE);
impl Process {
fn open(pid: DWORD) -> Result {
let pc = unsafe { OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_TERMINATE, 0, pid) };
- if pc == null_mut() {
+ if pc.is_null() {
return Err("!OpenProcess".to_string());
}
Ok(Process(pc))
diff --git a/src/canvas.rs b/src/canvas.rs
index e5275a00..f389d3b0 100644
--- a/src/canvas.rs
+++ b/src/canvas.rs
@@ -56,7 +56,7 @@ pub fn draw_data(terminal: &mut Terminal, app_state: &mu
.split(vertical_dialog_chunk[1]);
let help_text = [
- Text::raw("\nGeneral Keybinds\n"),
+ Text::raw("\nGeneral Keybindings\n"),
Text::raw("q, Ctrl-c to quit.\n"),
Text::raw("Ctrl-r to reset all data.\n"),
Text::raw("f to toggle freezing and unfreezing the display.\n"),
@@ -64,7 +64,7 @@ pub fn draw_data(terminal: &mut Terminal, app_state: &mu
Text::raw("Up and Down scrolls through a list.\n"),
Text::raw("Esc to close a dialog window (help or dd confirmation).\n"),
Text::raw("? to get this help screen.\n"),
- Text::raw("\n Process Panel Keybinds\n"),
+ Text::raw("\n Process Panel Keybindings\n"),
Text::raw("dd to kill the selected process.\n"),
Text::raw("c to sort by CPU usage.\n"),
Text::raw("m to sort by memory usage.\n"),
diff --git a/src/data_conversion.rs b/src/data_conversion.rs
index 7fd63b39..9c583fcd 100644
--- a/src/data_conversion.rs
+++ b/src/data_conversion.rs
@@ -289,13 +289,13 @@ pub fn convert_network_data_points(network_data: &[data_collection::network::Net
let rx_display = if let Some(last_num_bytes_entry) = network_data.last() {
let num_bytes = last_num_bytes_entry.rx;
if num_bytes < 1024 {
- format!("RX: {:5.*} B/s", 1, num_bytes as f64).to_string()
+ format!("RX: {:5.*} B/s", 1, num_bytes as f64)
} else if num_bytes < (1024 * 1024) {
- format!("RX: {:5.*}KiB/s", 1, num_bytes as f64 / 1024.0).to_string()
+ format!("RX: {:5.*}KiB/s", 1, num_bytes as f64 / 1024.0)
} else if num_bytes < (1024 * 1024 * 1024) {
- format!("RX: {:5.*}MiB/s", 1, num_bytes as f64 / 1024.0 / 1024.0).to_string()
+ format!("RX: {:5.*}MiB/s", 1, num_bytes as f64 / 1024.0 / 1024.0)
} else {
- format!("RX: {:5.*}GiB/s", 1, num_bytes as f64 / 1024.0 / 1024.0 / 1024.0).to_string()
+ format!("RX: {:5.*}GiB/s", 1, num_bytes as f64 / 1024.0 / 1024.0 / 1024.0)
}
} else {
"0.0B/s".to_string()
@@ -304,13 +304,13 @@ pub fn convert_network_data_points(network_data: &[data_collection::network::Net
let tx_display = if let Some(last_num_bytes_entry) = network_data.last() {
let num_bytes = last_num_bytes_entry.tx;
if num_bytes < 1024 {
- format!("TX: {:5.*} B/s", 1, num_bytes as f64).to_string()
+ format!("TX: {:5.*} B/s", 1, num_bytes as f64)
} else if num_bytes < (1024 * 1024) {
- format!("TX: {:5.*}KiB/s", 1, num_bytes as f64 / 1024.0).to_string()
+ format!("TX: {:5.*}KiB/s", 1, num_bytes as f64 / 1024.0)
} else if num_bytes < (1024 * 1024 * 1024) {
- format!("TX: {:5.*}MiB/s", 1, num_bytes as f64 / 1024.0 / 1024.0).to_string()
+ format!("TX: {:5.*}MiB/s", 1, num_bytes as f64 / 1024.0 / 1024.0)
} else {
- format!("TX: {:5.*}GiB/s", 1, num_bytes as f64 / 1024.0 / 1024.0 / 1024.0).to_string()
+ format!("TX: {:5.*}GiB/s", 1, num_bytes as f64 / 1024.0 / 1024.0 / 1024.0)
}
} else {
"0B.0/s".to_string()
diff --git a/src/main.rs b/src/main.rs
index f15090ff..439aea50 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -177,7 +177,7 @@ fn main() -> error::Result<()> {
// Event loop
let (rtx, rrx) = mpsc::channel();
{
- let tx = tx.clone();
+ let tx = tx;
let mut first_run = true;
let temp_type = app.temperature_type.clone();
thread::spawn(move || {
diff --git a/src/utils/error.rs b/src/utils/error.rs
index 666ca2f4..0c2dc3eb 100644
--- a/src/utils/error.rs
+++ b/src/utils/error.rs
@@ -65,7 +65,7 @@ impl From for BottomError {
impl From for BottomError {
fn from(err: std::string::String) -> Self {
- BottomError::GenericError { message: err.to_string() }
+ BottomError::GenericError { message: err }
}
}