mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-04 15:07:47 +00:00
refactor/polish ~ fix cargo clippy
complaints (redundant closure)
This commit is contained in:
parent
fa8540cb15
commit
2e90c78fae
12 changed files with 18 additions and 18 deletions
|
@ -475,7 +475,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
let options = crash_if_err!(EXIT_ERR, Options::from_matches(&matches));
|
||||
let paths: Vec<String> = matches
|
||||
.values_of("paths")
|
||||
.map(|v| v.map(|p| p.to_string()).collect())
|
||||
.map(|v| v.map(std::string::ToString::to_string).collect())
|
||||
.unwrap_or_default();
|
||||
|
||||
let (sources, target) = crash_if_err!(EXIT_ERR, parse_path_args(&paths, &options));
|
||||
|
@ -590,7 +590,7 @@ impl Options {
|
|||
let no_target_dir = matches.is_present(OPT_NO_TARGET_DIRECTORY);
|
||||
let target_dir = matches
|
||||
.value_of(OPT_TARGET_DIRECTORY)
|
||||
.map(|v| v.to_string());
|
||||
.map(std::string::ToString::to_string);
|
||||
|
||||
// Parse attributes to preserve
|
||||
let preserve_attributes: Vec<Attribute> = if matches.is_present(OPT_PRESERVE) {
|
||||
|
|
|
@ -120,7 +120,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
Ok(f) => {
|
||||
let fin = BufReader::new(f);
|
||||
result = parse(
|
||||
fin.lines().filter_map(|l| l.ok()),
|
||||
fin.lines().filter_map(std::result::Result::ok),
|
||||
out_format,
|
||||
matches.free[0].as_str(),
|
||||
)
|
||||
|
|
4
src/env/env.rs
vendored
4
src/env/env.rs
vendored
|
@ -159,11 +159,11 @@ fn run_env(args: Vec<String>) -> Result<(), i32> {
|
|||
let null = matches.is_present("null");
|
||||
let files = matches
|
||||
.values_of("file")
|
||||
.map(|v| v.collect())
|
||||
.map(std::iter::Iterator::collect)
|
||||
.unwrap_or_else(|| Vec::with_capacity(0));
|
||||
let unsets = matches
|
||||
.values_of("unset")
|
||||
.map(|v| v.collect())
|
||||
.map(std::iter::Iterator::collect)
|
||||
.unwrap_or_else(|| Vec::with_capacity(0));
|
||||
|
||||
let mut opts = Options {
|
||||
|
|
|
@ -164,7 +164,7 @@ impl<'a> Iterator for FileLines<'a> {
|
|||
// emit a blank line
|
||||
// Err(true) indicates that this was a linebreak,
|
||||
// which is important to know when detecting mail headers
|
||||
if n.chars().all(|c| c.is_whitespace()) {
|
||||
if n.chars().all(char::is_whitespace) {
|
||||
return Some(Line::NoFormatLine("".to_owned(), true));
|
||||
}
|
||||
|
||||
|
@ -180,7 +180,7 @@ impl<'a> Iterator for FileLines<'a> {
|
|||
// following line)
|
||||
n[poffset + self.opts.prefix.len()..]
|
||||
.chars()
|
||||
.all(|c| c.is_whitespace())
|
||||
.all(char::is_whitespace)
|
||||
{
|
||||
return Some(Line::NoFormatLine(n, false));
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ fn fold_file<T: Read>(mut file: BufReader<T>, bytes: bool, spaces: bool, width:
|
|||
let slice = {
|
||||
let slice = &line[i..i + width];
|
||||
if spaces && i + width < len {
|
||||
match slice.rfind(|ch: char| ch.is_whitespace()) {
|
||||
match slice.rfind(char::is_whitespace) {
|
||||
Some(m) => &slice[..=m],
|
||||
None => slice,
|
||||
}
|
||||
|
|
|
@ -297,7 +297,7 @@ fn directory(paths: &[PathBuf], b: Behaviour) -> i32 {
|
|||
/// Test if the path is a a new file path that can be
|
||||
/// created immediately
|
||||
fn is_new_file_path(path: &Path) -> bool {
|
||||
path.is_file() || !path.exists() && path.parent().map(|p| p.is_dir()).unwrap_or(true)
|
||||
path.is_file() || !path.exists() && path.parent().map(std::path::Path::is_dir).unwrap_or(true)
|
||||
}
|
||||
|
||||
/// Perform an install, given a list of paths and behaviour.
|
||||
|
|
|
@ -289,8 +289,8 @@ fn should_display(entry: &DirEntry, options: &getopts::Matches) -> bool {
|
|||
}
|
||||
|
||||
fn enter_directory(dir: &PathBuf, options: &getopts::Matches) {
|
||||
let mut entries =
|
||||
safe_unwrap!(fs::read_dir(dir).and_then(|e| e.collect::<Result<Vec<_>, _>>()));
|
||||
let mut entries: Vec<_> =
|
||||
safe_unwrap!(fs::read_dir(dir).and_then(std::iter::Iterator::collect));
|
||||
|
||||
entries.retain(|e| should_display(e, options));
|
||||
|
||||
|
|
|
@ -123,14 +123,14 @@ With no FILE, or when FILE is -, read standard input.",
|
|||
let mut evec = matches
|
||||
.free
|
||||
.iter()
|
||||
.map(|a| a.as_bytes())
|
||||
.map(std::string::String::as_bytes)
|
||||
.collect::<Vec<&[u8]>>();
|
||||
find_seps(&mut evec, sep);
|
||||
shuf_bytes(&mut evec, repeat, count, sep, output, random);
|
||||
}
|
||||
Mode::InputRange((b, e)) => {
|
||||
let rvec = (b..e).map(|x| format!("{}", x)).collect::<Vec<String>>();
|
||||
let mut rvec = rvec.iter().map(|a| a.as_bytes()).collect::<Vec<&[u8]>>();
|
||||
let mut rvec = rvec.iter().map(std::string::String::as_bytes).collect::<Vec<&[u8]>>();
|
||||
shuf_bytes(&mut rvec, repeat, count, sep, output, random);
|
||||
}
|
||||
Mode::Default => {
|
||||
|
|
|
@ -482,8 +482,8 @@ impl Stater {
|
|||
);
|
||||
let mut mount_list = reader
|
||||
.lines()
|
||||
.filter_map(|s| s.ok())
|
||||
.filter_map(|line| line.split_whitespace().nth(1).map(|s| s.to_owned()))
|
||||
.filter_map(std::result::Result::ok)
|
||||
.filter_map(|line| line.split_whitespace().nth(1).map(std::borrow::ToOwned::to_owned))
|
||||
.collect::<Vec<String>>();
|
||||
// Reverse sort. The longer comes first.
|
||||
mount_list.sort_by(|a, b| b.cmp(a));
|
||||
|
|
|
@ -94,7 +94,7 @@ fn print_usage(opts: &Options) {
|
|||
|
||||
fn parse_size(size: &str) -> Option<u64> {
|
||||
let ext = size.trim_start_matches(|c: char| c.is_digit(10));
|
||||
let num = size.trim_end_matches(|c: char| c.is_alphabetic());
|
||||
let num = size.trim_end_matches(char::is_alphabetic);
|
||||
let mut recovered = num.to_owned();
|
||||
recovered.push_str(ext);
|
||||
if recovered != size {
|
||||
|
|
|
@ -67,7 +67,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
fn exec(filename: &str) {
|
||||
let mut users = Utmpx::iter_all_records()
|
||||
.read_from(filename)
|
||||
.filter(|ut| ut.is_user_process())
|
||||
.filter(uucore::utmpx::Utmpx::is_user_process)
|
||||
.map(|ut| ut.user())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
|
|
@ -311,7 +311,7 @@ impl Who {
|
|||
if self.short_list {
|
||||
let users = Utmpx::iter_all_records()
|
||||
.read_from(f)
|
||||
.filter(|ut| ut.is_user_process())
|
||||
.filter(uucore::utmpx::Utmpx::is_user_process)
|
||||
.map(|ut| ut.user())
|
||||
.collect::<Vec<_>>();
|
||||
println!("{}", users.join(" "));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue