1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

refactor ~ reduce excessive use of scope prefixes

This commit is contained in:
Roy Ivy III 2020-04-04 01:02:19 -05:00
parent 78d55f0e32
commit 156502a332
12 changed files with 23 additions and 30 deletions

View file

@ -55,6 +55,7 @@ use std::os::unix::io::IntoRawFd;
use std::os::windows::ffi::OsStrExt;
use std::path::{Path, PathBuf, StripPrefixError};
use std::str::FromStr;
use std::string::ToString;
use uucore::fs::{canonicalize, CanonicalizeMode};
use walkdir::WalkDir;
@ -477,7 +478,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(std::string::ToString::to_string).collect())
.map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default();
let (sources, target) = crash_if_err!(EXIT_ERR, parse_path_args(&paths, &options));
@ -593,7 +594,7 @@ impl Options {
let no_target_dir = matches.is_present(OPT_NO_TARGET_DIRECTORY);
let target_dir = matches
.value_of(OPT_TARGET_DIRECTORY)
.map(std::string::ToString::to_string);
.map(ToString::to_string);
// Parse attributes to preserve
let preserve_attributes: Vec<Attribute> = if matches.is_present(OPT_PRESERVE) {

View file

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

5
src/env/env.rs vendored
View file

@ -18,6 +18,7 @@ use ini::Ini;
use std::borrow::Cow;
use std::env;
use std::io::{self, Write};
use std::iter::Iterator;
use std::process::Command;
const USAGE: &str = "env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]";
@ -160,11 +161,11 @@ fn run_env(args: Vec<String>) -> Result<(), i32> {
let null = matches.is_present("null");
let files = matches
.values_of("file")
.map(std::iter::Iterator::collect)
.map(Iterator::collect)
.unwrap_or_else(|| Vec::with_capacity(0));
let unsets = matches
.values_of("unset")
.map(std::iter::Iterator::collect)
.map(Iterator::collect)
.unwrap_or_else(|| Vec::with_capacity(0));
let mut opts = Options {

View file

@ -32,6 +32,7 @@ use regex::Regex;
use sha1::Sha1;
use sha2::{Sha224, Sha256, Sha384, Sha512};
use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512, Shake128, Shake256};
use std::cmp::Ordering;
use std::fs::File;
use std::io::{self, stdin, BufRead, BufReader, Read};
use std::path::Path;
@ -503,12 +504,8 @@ fn hashsum(
}
if !status {
match bad_format.cmp(&1) {
std::cmp::Ordering::Equal => {
show_warning!("{} line is improperly formatted", bad_format)
}
std::cmp::Ordering::Greater => {
show_warning!("{} lines are improperly formatted", bad_format)
}
Ordering::Equal => show_warning!("{} line is improperly formatted", bad_format),
Ordering::Greater => show_warning!("{} lines are improperly formatted", bad_format),
_ => {}
};
if failed > 0 {

View file

@ -364,7 +364,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(std::path::Path::is_dir).unwrap_or(true)
path.is_file() || !path.exists() && path.parent().map(Path::is_dir).unwrap_or(true)
}
/// Perform an install, given a list of paths and behaviour.

View file

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

View file

@ -18,6 +18,7 @@ extern crate uucore;
use libc::{c_char, c_int, execvp};
use std::ffi::CString;
use std::io::Error;
use std::ptr;
const NAME: &str = "nice";
const VERSION: &str = env!("CARGO_PKG_VERSION");
@ -120,7 +121,7 @@ process).",
.map(|x| CString::new(x.as_bytes()).unwrap())
.collect();
let mut args: Vec<*const c_char> = cstrs.iter().map(|s| s.as_ptr()).collect();
args.push(std::ptr::null::<c_char>());
args.push(ptr::null::<c_char>());
unsafe {
execvp(args[0], args.as_mut_ptr());
}

View file

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

View file

@ -15,6 +15,7 @@ pub use libc::{
S_IFSOCK, S_IRGRP, S_IROTH, S_IRUSR, S_ISGID, S_ISUID, S_ISVTX, S_IWGRP, S_IWOTH, S_IWUSR,
S_IXGRP, S_IXOTH, S_IXUSR,
};
use std::time::UNIX_EPOCH;
pub trait BirthTime {
fn pretty_birth(&self) -> String;
@ -26,7 +27,7 @@ impl BirthTime for Metadata {
fn pretty_birth(&self) -> String {
self.created()
.ok()
.and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok())
.and_then(|t| t.duration_since(UNIX_EPOCH).ok())
.map(|e| pretty_time(e.as_secs() as i64, i64::from(e.subsec_nanos())))
.unwrap_or_else(|| "-".to_owned())
}
@ -34,7 +35,7 @@ impl BirthTime for Metadata {
fn birth(&self) -> String {
self.created()
.ok()
.and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok())
.and_then(|t| t.duration_since(UNIX_EPOCH).ok())
.map(|e| format!("{}", e.as_secs()))
.unwrap_or_else(|| "0".to_owned())
}

View file

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

View file

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

View file

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