From e79908b4fe3b8be358097b23e3715fe7d72d2470 Mon Sep 17 00:00:00 2001 From: "Hatter Jiang@Pixelbook" Date: Sun, 2 Aug 2020 11:44:56 +0800 Subject: [PATCH] style: fix clippy --- Cargo.toml | 2 +- src/lib.rs | 7 ++----- src/util_cmd.rs | 3 +-- src/util_file.rs | 14 +++++++------- src/util_io.rs | 15 ++++----------- src/util_msg.rs | 4 ++-- 6 files changed, 17 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 67f590b..9f2eeb3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rust_util" -version = "0.5.0" +version = "0.6.0" authors = ["Hatter Jiang "] edition = "2018" description = "Hatter's Rust Util" diff --git a/src/lib.rs b/src/lib.rs index 516d99c..ab79e86 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ extern crate lazy_static; extern crate term; -use std::io::{ Error, ErrorKind, }; +use std::io::{ Error, ErrorKind }; pub mod util_io; pub mod util_os; @@ -16,11 +16,8 @@ pub mod util_time; /// iff!(condition, result_when_true, result_when_false) #[macro_export] macro_rules! iff { - ($c:expr, $t:expr, $f:expr) => { - if $c { $t } else { $f } - }; + ($c:expr, $t:expr, $f:expr) => ( if $c { $t } else { $f } ) } - #[macro_export] macro_rules! information { ($($arg:tt)+) => ( crate::util_msg::print_info(&format!($($arg)+)); ) } diff --git a/src/util_cmd.rs b/src/util_cmd.rs index 4116a85..11864f5 100644 --- a/src/util_cmd.rs +++ b/src/util_cmd.rs @@ -1,6 +1,5 @@ - use std::{ - io::{self, Error, ErrorKind}, + io::{ self, Error, ErrorKind }, process::Command, }; diff --git a/src/util_file.rs b/src/util_file.rs index 13e24d2..75e93d4 100644 --- a/src/util_file.rs +++ b/src/util_file.rs @@ -1,9 +1,9 @@ use std::{ env, - fs::{self, File}, - io::{Lines, BufReader}, - path::{Path, PathBuf}, + fs::{ self, File }, + io::{ Lines, BufReader }, + path::{ Path, PathBuf }, }; use super::{ @@ -143,8 +143,8 @@ pub fn walk_dir(dir: &Path, func_walk_error: &FError, func_process_file: &FProcess, func_filter_dir: &FFilter) -> XResult<()> - where FError: Fn(&Path, Box) -> (), - FProcess: Fn(&Path) -> (), + where FError: Fn(&Path, Box), + FProcess: Fn(&Path), FFilter: Fn(&Path) -> bool { walk_dir_with_depth_check(&mut 0u32, dir, func_walk_error, func_process_file, func_filter_dir) } @@ -153,8 +153,8 @@ fn walk_dir_with_depth_check(depth: &mut u32, dir: &P func_walk_error: &FError, func_process_file: &FProcess, func_filter_dir: &FFilter) -> XResult<()> - where FError: Fn(&Path, Box) -> (), - FProcess: Fn(&Path) -> (), + where FError: Fn(&Path, Box), + FProcess: Fn(&Path), FFilter: Fn(&Path) -> bool { if *depth > 100u32 { return Err(new_box_ioerror(&format!("Depth exceed, depth: {}, path: {:?}", *depth, dir))); diff --git a/src/util_io.rs b/src/util_io.rs index dd9b189..365b9cb 100644 --- a/src/util_io.rs +++ b/src/util_io.rs @@ -1,11 +1,7 @@ - use std::{ fs::File, - io::{self, - ErrorKind, - prelude::*, - }, - time::{SystemTime, Duration}, + io::{ self, ErrorKind, prelude::* }, + time::{ SystemTime, Duration }, }; use super::{ XResult, new_box_ioerror, }; @@ -66,12 +62,9 @@ pub fn print_status_last_line(head: &str, total: i64, written: i64, cost: Durati pub fn copy_io_with_head(reader: &mut R, writer: &mut W, total: i64, head: &str) -> io::Result where R: io::Read, W: io::Write { - //let written_cell = RefCell::new(0u64); let start = SystemTime::now(); let written = copy_io_callback(reader, writer, total, &|total, written, _len| { - //written_cell.replace_with(|&mut w| w + len as u64); - //let written = *written_cell.borrow(); - let cost = SystemTime::now().duration_since(start.clone()).unwrap(); + let cost = SystemTime::now().duration_since(start).unwrap(); print_status_last_line(head, total, written as i64, cost); }); println!(); @@ -81,7 +74,7 @@ pub fn copy_io_with_head(reader: &mut R, writer: &mut W, t pub fn copy_io_callback(reader: &mut R, writer: &mut W, total: i64, callback: &FCallback) -> io::Result where R: io::Read, W: io::Write, - FCallback: Fn(i64, u64, usize) -> () { + FCallback: Fn(i64, u64, usize) { let mut written = 0u64; let mut buf: [u8; DEFAULT_BUF_SIZE] = [0u8; DEFAULT_BUF_SIZE]; loop { diff --git a/src/util_msg.rs b/src/util_msg.rs index 533eff8..e9cfd01 100644 --- a/src/util_msg.rs +++ b/src/util_msg.rs @@ -1,6 +1,6 @@ use std::{ - io::{self, Write}, - sync::{Arc, Mutex}, + io::{ self, Write }, + sync::{ Arc, Mutex }, }; lazy_static! {