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]
|
[package]
|
||||||
name = "rust_util"
|
name = "rust_util"
|
||||||
version = "0.5.0"
|
version = "0.6.0"
|
||||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Hatter's Rust Util"
|
description = "Hatter's Rust Util"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
extern crate term;
|
extern crate term;
|
||||||
|
|
||||||
use std::io::{ Error, ErrorKind, };
|
use std::io::{ Error, ErrorKind };
|
||||||
|
|
||||||
pub mod util_io;
|
pub mod util_io;
|
||||||
pub mod util_os;
|
pub mod util_os;
|
||||||
@@ -16,11 +16,8 @@ pub mod util_time;
|
|||||||
|
|
||||||
/// iff!(condition, result_when_true, result_when_false)
|
/// iff!(condition, result_when_true, result_when_false)
|
||||||
#[macro_export] macro_rules! iff {
|
#[macro_export] macro_rules! iff {
|
||||||
($c:expr, $t:expr, $f:expr) => {
|
($c:expr, $t:expr, $f:expr) => ( if $c { $t } else { $f } )
|
||||||
if $c { $t } else { $f }
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export] macro_rules! information {
|
#[macro_export] macro_rules! information {
|
||||||
($($arg:tt)+) => ( crate::util_msg::print_info(&format!($($arg)+)); )
|
($($arg:tt)+) => ( crate::util_msg::print_info(&format!($($arg)+)); )
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
io::{self, Error, ErrorKind},
|
io::{ self, Error, ErrorKind },
|
||||||
process::Command,
|
process::Command,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
env,
|
||||||
fs::{self, File},
|
fs::{ self, File },
|
||||||
io::{Lines, BufReader},
|
io::{ Lines, BufReader },
|
||||||
path::{Path, PathBuf},
|
path::{ Path, PathBuf },
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
@@ -143,8 +143,8 @@ pub fn walk_dir<FError, FProcess, FFilter>(dir: &Path,
|
|||||||
func_walk_error: &FError,
|
func_walk_error: &FError,
|
||||||
func_process_file: &FProcess,
|
func_process_file: &FProcess,
|
||||||
func_filter_dir: &FFilter) -> XResult<()>
|
func_filter_dir: &FFilter) -> XResult<()>
|
||||||
where FError: Fn(&Path, Box<dyn std::error::Error>) -> (),
|
where FError: Fn(&Path, Box<dyn std::error::Error>),
|
||||||
FProcess: Fn(&Path) -> (),
|
FProcess: Fn(&Path),
|
||||||
FFilter: Fn(&Path) -> bool {
|
FFilter: Fn(&Path) -> bool {
|
||||||
walk_dir_with_depth_check(&mut 0u32, dir, func_walk_error, func_process_file, func_filter_dir)
|
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_walk_error: &FError,
|
||||||
func_process_file: &FProcess,
|
func_process_file: &FProcess,
|
||||||
func_filter_dir: &FFilter) -> XResult<()>
|
func_filter_dir: &FFilter) -> XResult<()>
|
||||||
where FError: Fn(&Path, Box<dyn std::error::Error>) -> (),
|
where FError: Fn(&Path, Box<dyn std::error::Error>),
|
||||||
FProcess: Fn(&Path) -> (),
|
FProcess: Fn(&Path),
|
||||||
FFilter: Fn(&Path) -> bool {
|
FFilter: Fn(&Path) -> bool {
|
||||||
if *depth > 100u32 {
|
if *depth > 100u32 {
|
||||||
return Err(new_box_ioerror(&format!("Depth exceed, depth: {}, path: {:?}", *depth, dir)));
|
return Err(new_box_ioerror(&format!("Depth exceed, depth: {}, path: {:?}", *depth, dir)));
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{self,
|
io::{ self, ErrorKind, prelude::* },
|
||||||
ErrorKind,
|
time::{ SystemTime, Duration },
|
||||||
prelude::*,
|
|
||||||
},
|
|
||||||
time::{SystemTime, Duration},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{ XResult, new_box_ioerror, };
|
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>
|
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 {
|
where R: io::Read, W: io::Write {
|
||||||
//let written_cell = RefCell::new(0u64);
|
|
||||||
let start = SystemTime::now();
|
let start = SystemTime::now();
|
||||||
let written = copy_io_callback(reader, writer, total, &|total, written, _len| {
|
let written = copy_io_callback(reader, writer, total, &|total, written, _len| {
|
||||||
//written_cell.replace_with(|&mut w| w + len as u64);
|
let cost = SystemTime::now().duration_since(start).unwrap();
|
||||||
//let written = *written_cell.borrow();
|
|
||||||
let cost = SystemTime::now().duration_since(start.clone()).unwrap();
|
|
||||||
print_status_last_line(head, total, written as i64, cost);
|
print_status_last_line(head, total, written as i64, cost);
|
||||||
});
|
});
|
||||||
println!();
|
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>
|
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,
|
where R: io::Read,
|
||||||
W: io::Write,
|
W: io::Write,
|
||||||
FCallback: Fn(i64, u64, usize) -> () {
|
FCallback: Fn(i64, u64, usize) {
|
||||||
let mut written = 0u64;
|
let mut written = 0u64;
|
||||||
let mut buf: [u8; DEFAULT_BUF_SIZE] = [0u8; DEFAULT_BUF_SIZE];
|
let mut buf: [u8; DEFAULT_BUF_SIZE] = [0u8; DEFAULT_BUF_SIZE];
|
||||||
loop {
|
loop {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::{
|
use std::{
|
||||||
io::{self, Write},
|
io::{ self, Write },
|
||||||
sync::{Arc, Mutex},
|
sync::{ Arc, Mutex },
|
||||||
};
|
};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
|
|||||||
Reference in New Issue
Block a user