From 5074a46c61029d25ddd56724287461cff20c836e Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 11 Jan 2020 11:51:28 +0800 Subject: [PATCH] fix clippy --- src/util_file.rs | 8 ++++---- src/util_msg.rs | 4 ++-- src/util_size.rs | 24 ++++++++++++------------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/util_file.rs b/src/util_file.rs index 2326930..d9fb589 100644 --- a/src/util_file.rs +++ b/src/util_file.rs @@ -12,9 +12,10 @@ use super::{ }; pub fn get_home_str() -> Option { - match util_os::is_macos_or_linux() { - true => env::var("HOME").ok(), - false => None, + if util_os::is_macos_or_linux() { + env::var("HOME").ok() + } else { + None } } @@ -84,7 +85,6 @@ fn walk_dir_with_depth_check(depth: &mut u32, dir: &P match walk_dir_with_depth_check(depth, &sub_dir, func_walk_error, func_process_file, func_filter_dir) { Err(err) => { func_walk_error(&sub_dir, err); - () }, Ok(_) => (), } diff --git a/src/util_msg.rs b/src/util_msg.rs index 136e0c9..f8a92ae 100644 --- a/src/util_msg.rs +++ b/src/util_msg.rs @@ -9,8 +9,8 @@ lazy_static! { pub enum MessageType { INFO, OK, WARN, ERROR, DEBUG, } pub fn is_atty() -> bool{ - let isatty = unsafe { libc::isatty(libc::STDOUT_FILENO as i32) } != 0; - isatty + let stdout_fileno = unsafe { libc::isatty(libc::STDOUT_FILENO as i32) }; + stdout_fileno != 0 } pub fn print_color(color: Option, is_bold: bool, m: &str) { diff --git a/src/util_size.rs b/src/util_size.rs index e40e1d5..ff525e6 100644 --- a/src/util_size.rs +++ b/src/util_size.rs @@ -9,20 +9,20 @@ pub const SIZE_TB: i64 = SIZE_PB * SIZE_KB; pub fn parse_size(size: &str) -> XResult { let lower_size = size.to_lowercase(); - let no_last_b_size = if lower_size.ends_with("b") { + let no_last_b_size = if lower_size.ends_with('b') { &lower_size[0..lower_size.len()-1] } else { &lower_size }; - if no_last_b_size.ends_with("k") { + if no_last_b_size.ends_with('k') { return Ok((SIZE_KB as f64 * no_last_b_size[0..no_last_b_size.len()-1].parse::()?) as i64); - } else if no_last_b_size.ends_with("m") { + } else if no_last_b_size.ends_with('m') { return Ok((SIZE_MB as f64 * no_last_b_size[0..no_last_b_size.len()-1].parse::()?) as i64); - } else if no_last_b_size.ends_with("g") { + } else if no_last_b_size.ends_with('g') { return Ok((SIZE_GB as f64 * no_last_b_size[0..no_last_b_size.len()-1].parse::()?) as i64); - } else if no_last_b_size.ends_with("t") { + } else if no_last_b_size.ends_with('t') { return Ok((SIZE_TB as f64 * no_last_b_size[0..no_last_b_size.len()-1].parse::()?) as i64); - } else if no_last_b_size.ends_with("p") { + } else if no_last_b_size.ends_with('p') { return Ok((SIZE_PB as f64 * no_last_b_size[0..no_last_b_size.len()-1].parse::()?) as i64); } @@ -31,16 +31,16 @@ pub fn parse_size(size: &str) -> XResult { pub fn get_display_size(size: i64) -> String { if size < SIZE_KB { - return size.to_string(); + size.to_string() } else if size < SIZE_MB { - return format!("{:.*}KB", 2, (size as f64) / 1024.); + format!("{:.*}KB", 2, (size as f64) / 1024.) } else if size < SIZE_GB { - return format!("{:.*}MB", 2, (size as f64) / 1024. / 1024.); + format!("{:.*}MB", 2, (size as f64) / 1024. / 1024.) } else if size < SIZE_TB { - return format!("{:.*}GB", 2, (size as f64) / 1024. / 1024. / 1024.); + format!("{:.*}GB", 2, (size as f64) / 1024. / 1024. / 1024.) } else if size < SIZE_PB { - return format!("{:.*}TB", 2, (size as f64) / 1024. / 1024. / 1024. / 1024.); + format!("{:.*}TB", 2, (size as f64) / 1024. / 1024. / 1024. / 1024.) } else { - return format!("{:.*}PB", 2, (size as f64) / 1024. / 1024. / 1024. / 1024. / 1024.); + format!("{:.*}PB", 2, (size as f64) / 1024. / 1024. / 1024. / 1024. / 1024.) } }