mirror of
https://github.com/jht5945/rust_util.git
synced 2025-12-27 15:40:03 +08:00
style: fix clippy
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rust_util"
|
||||
version = "0.5.0"
|
||||
version = "0.6.0"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
description = "Hatter's Rust Util"
|
||||
|
||||
@@ -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)+)); )
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
|
||||
use std::{
|
||||
io::{self, Error, ErrorKind},
|
||||
io::{ self, Error, ErrorKind },
|
||||
process::Command,
|
||||
};
|
||||
|
||||
|
||||
@@ -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<FError, FProcess, FFilter>(dir: &Path,
|
||||
func_walk_error: &FError,
|
||||
func_process_file: &FProcess,
|
||||
func_filter_dir: &FFilter) -> XResult<()>
|
||||
where FError: Fn(&Path, Box<dyn std::error::Error>) -> (),
|
||||
FProcess: Fn(&Path) -> (),
|
||||
where FError: Fn(&Path, Box<dyn std::error::Error>),
|
||||
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<FError, FProcess, FFilter>(depth: &mut u32, dir: &P
|
||||
func_walk_error: &FError,
|
||||
func_process_file: &FProcess,
|
||||
func_filter_dir: &FFilter) -> XResult<()>
|
||||
where FError: Fn(&Path, Box<dyn std::error::Error>) -> (),
|
||||
FProcess: Fn(&Path) -> (),
|
||||
where FError: Fn(&Path, Box<dyn std::error::Error>),
|
||||
FProcess: Fn(&Path),
|
||||
FFilter: Fn(&Path) -> bool {
|
||||
if *depth > 100u32 {
|
||||
return Err(new_box_ioerror(&format!("Depth exceed, depth: {}, path: {:?}", *depth, dir)));
|
||||
|
||||
@@ -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<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W, total: i64, head: &str) -> io::Result<u64>
|
||||
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<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W, t
|
||||
pub fn copy_io_callback<R: ?Sized, W: ?Sized, FCallback>(reader: &mut R, writer: &mut W, total: i64, callback: &FCallback) -> io::Result<u64>
|
||||
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 {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::{
|
||||
io::{self, Write},
|
||||
sync::{Arc, Mutex},
|
||||
io::{ self, Write },
|
||||
sync::{ Arc, Mutex },
|
||||
};
|
||||
|
||||
lazy_static! {
|
||||
|
||||
Reference in New Issue
Block a user