1
Fork 0
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:
Roy Ivy III 2019-12-26 11:12:33 -06:00
parent fa8540cb15
commit 2e90c78fae
12 changed files with 18 additions and 18 deletions

View file

@ -475,7 +475,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
let options = crash_if_err!(EXIT_ERR, Options::from_matches(&matches)); let options = crash_if_err!(EXIT_ERR, Options::from_matches(&matches));
let paths: Vec<String> = matches let paths: Vec<String> = matches
.values_of("paths") .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(); .unwrap_or_default();
let (sources, target) = crash_if_err!(EXIT_ERR, parse_path_args(&paths, &options)); 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 no_target_dir = matches.is_present(OPT_NO_TARGET_DIRECTORY);
let target_dir = matches let target_dir = matches
.value_of(OPT_TARGET_DIRECTORY) .value_of(OPT_TARGET_DIRECTORY)
.map(|v| v.to_string()); .map(std::string::ToString::to_string);
// Parse attributes to preserve // Parse attributes to preserve
let preserve_attributes: Vec<Attribute> = if matches.is_present(OPT_PRESERVE) { let preserve_attributes: Vec<Attribute> = if matches.is_present(OPT_PRESERVE) {

View file

@ -120,7 +120,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
Ok(f) => { Ok(f) => {
let fin = BufReader::new(f); let fin = BufReader::new(f);
result = parse( result = parse(
fin.lines().filter_map(|l| l.ok()), fin.lines().filter_map(std::result::Result::ok),
out_format, out_format,
matches.free[0].as_str(), matches.free[0].as_str(),
) )

4
src/env/env.rs vendored
View file

@ -159,11 +159,11 @@ fn run_env(args: Vec<String>) -> Result<(), i32> {
let null = matches.is_present("null"); let null = matches.is_present("null");
let files = matches let files = matches
.values_of("file") .values_of("file")
.map(|v| v.collect()) .map(std::iter::Iterator::collect)
.unwrap_or_else(|| Vec::with_capacity(0)); .unwrap_or_else(|| Vec::with_capacity(0));
let unsets = matches let unsets = matches
.values_of("unset") .values_of("unset")
.map(|v| v.collect()) .map(std::iter::Iterator::collect)
.unwrap_or_else(|| Vec::with_capacity(0)); .unwrap_or_else(|| Vec::with_capacity(0));
let mut opts = Options { let mut opts = Options {

View file

@ -164,7 +164,7 @@ impl<'a> Iterator for FileLines<'a> {
// emit a blank line // emit a blank line
// Err(true) indicates that this was a linebreak, // Err(true) indicates that this was a linebreak,
// which is important to know when detecting mail headers // 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)); return Some(Line::NoFormatLine("".to_owned(), true));
} }
@ -180,7 +180,7 @@ impl<'a> Iterator for FileLines<'a> {
// following line) // following line)
n[poffset + self.opts.prefix.len()..] n[poffset + self.opts.prefix.len()..]
.chars() .chars()
.all(|c| c.is_whitespace()) .all(char::is_whitespace)
{ {
return Some(Line::NoFormatLine(n, false)); return Some(Line::NoFormatLine(n, false));
} }

View file

@ -110,7 +110,7 @@ fn fold_file<T: Read>(mut file: BufReader<T>, bytes: bool, spaces: bool, width:
let slice = { let slice = {
let slice = &line[i..i + width]; let slice = &line[i..i + width];
if spaces && i + width < len { if spaces && i + width < len {
match slice.rfind(|ch: char| ch.is_whitespace()) { match slice.rfind(char::is_whitespace) {
Some(m) => &slice[..=m], Some(m) => &slice[..=m],
None => slice, None => slice,
} }

View file

@ -297,7 +297,7 @@ fn directory(paths: &[PathBuf], b: Behaviour) -> i32 {
/// Test if the path is a a new file path that can be /// Test if the path is a a new file path that can be
/// created immediately /// created immediately
fn is_new_file_path(path: &Path) -> bool { 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. /// Perform an install, given a list of paths and behaviour.

View file

@ -289,8 +289,8 @@ fn should_display(entry: &DirEntry, options: &getopts::Matches) -> bool {
} }
fn enter_directory(dir: &PathBuf, options: &getopts::Matches) { fn enter_directory(dir: &PathBuf, options: &getopts::Matches) {
let mut entries = let mut entries: Vec<_> =
safe_unwrap!(fs::read_dir(dir).and_then(|e| e.collect::<Result<Vec<_>, _>>())); safe_unwrap!(fs::read_dir(dir).and_then(std::iter::Iterator::collect));
entries.retain(|e| should_display(e, options)); entries.retain(|e| should_display(e, options));

View file

@ -123,14 +123,14 @@ With no FILE, or when FILE is -, read standard input.",
let mut evec = matches let mut evec = matches
.free .free
.iter() .iter()
.map(|a| a.as_bytes()) .map(std::string::String::as_bytes)
.collect::<Vec<&[u8]>>(); .collect::<Vec<&[u8]>>();
find_seps(&mut evec, sep); find_seps(&mut evec, sep);
shuf_bytes(&mut evec, repeat, count, sep, output, random); shuf_bytes(&mut evec, repeat, count, sep, output, random);
} }
Mode::InputRange((b, e)) => { Mode::InputRange((b, e)) => {
let rvec = (b..e).map(|x| format!("{}", x)).collect::<Vec<String>>(); 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); shuf_bytes(&mut rvec, repeat, count, sep, output, random);
} }
Mode::Default => { Mode::Default => {

View file

@ -482,8 +482,8 @@ impl Stater {
); );
let mut mount_list = reader let mut mount_list = reader
.lines() .lines()
.filter_map(|s| s.ok()) .filter_map(std::result::Result::ok)
.filter_map(|line| line.split_whitespace().nth(1).map(|s| s.to_owned())) .filter_map(|line| line.split_whitespace().nth(1).map(std::borrow::ToOwned::to_owned))
.collect::<Vec<String>>(); .collect::<Vec<String>>();
// Reverse sort. The longer comes first. // Reverse sort. The longer comes first.
mount_list.sort_by(|a, b| b.cmp(a)); mount_list.sort_by(|a, b| b.cmp(a));

View file

@ -94,7 +94,7 @@ fn print_usage(opts: &Options) {
fn parse_size(size: &str) -> Option<u64> { fn parse_size(size: &str) -> Option<u64> {
let ext = size.trim_start_matches(|c: char| c.is_digit(10)); 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(); let mut recovered = num.to_owned();
recovered.push_str(ext); recovered.push_str(ext);
if recovered != size { if recovered != size {

View file

@ -67,7 +67,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
fn exec(filename: &str) { fn exec(filename: &str) {
let mut users = Utmpx::iter_all_records() let mut users = Utmpx::iter_all_records()
.read_from(filename) .read_from(filename)
.filter(|ut| ut.is_user_process()) .filter(uucore::utmpx::Utmpx::is_user_process)
.map(|ut| ut.user()) .map(|ut| ut.user())
.collect::<Vec<_>>(); .collect::<Vec<_>>();

View file

@ -311,7 +311,7 @@ impl Who {
if self.short_list { if self.short_list {
let users = Utmpx::iter_all_records() let users = Utmpx::iter_all_records()
.read_from(f) .read_from(f)
.filter(|ut| ut.is_user_process()) .filter(uucore::utmpx::Utmpx::is_user_process)
.map(|ut| ut.user()) .map(|ut| ut.user())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
println!("{}", users.join(" ")); println!("{}", users.join(" "));