Minor changes to improve readability

This patch makes minor changes to make the code a little easier to
understand. For example, using the `?` operator in some fns that return
an `Option` type.
This commit is contained in:
Josh Leeb-du Toit 2018-10-04 00:48:38 +10:00 committed by David Peter
parent cb1cfa108b
commit 8691ab4bed
3 changed files with 13 additions and 27 deletions

View file

@ -29,12 +29,11 @@ pub fn execute_command(mut cmd: Command, out_perm: Arc<Mutex<()>>) {
let _ = stdout.lock().write_all(&output.stdout);
let _ = stderr.lock().write_all(&output.stderr);
}
Err(why) => {
if why.kind() == io::ErrorKind::NotFound {
Err(ref why) if why.kind() == io::ErrorKind::NotFound => {
eprintln!("fd: execution error: command not found");
} else {
}
Err(why) => {
eprintln!("fd: execution error: {}", why);
}
}
}
}

View file

@ -17,12 +17,12 @@ use ignore::DirEntry;
pub fn path_absolute_form(path: &Path) -> io::Result<PathBuf> {
if path.is_absolute() {
Ok(path.to_path_buf())
} else {
return Ok(path.to_path_buf());
}
let path = path.strip_prefix(".").unwrap_or(path);
current_dir().map(|path_buf| path_buf.join(path))
}
}
pub fn absolute_path(path: &Path) -> io::Result<PathBuf> {
let path_buf = path_absolute_form(path)?;
@ -42,11 +42,7 @@ pub fn absolute_path(path: &Path) -> io::Result<PathBuf> {
// Path::is_dir() is not guaranteed to be intuitively correct for "." and ".."
// See: https://github.com/rust-lang/rust/issues/45302
pub fn is_dir(path: &Path) -> bool {
if path.file_name().is_some() {
path.is_dir()
} else {
path.is_dir() && path.canonicalize().is_ok()
}
path.is_dir() && (path.file_name().is_some() || path.canonicalize().is_ok())
}
#[cfg(any(unix, target_os = "redox"))]

View file

@ -66,20 +66,11 @@ impl SizeFilter {
return None;
}
let captures = match SIZE_CAPTURES.captures(s) {
Some(cap) => cap,
None => return None,
};
let captures = SIZE_CAPTURES.captures(s)?;
let limit_kind = captures.get(1).map_or("+", |m| m.as_str());
let quantity = match captures.get(2) {
None => return None,
Some(v) => match v.as_str().parse::<u64>() {
Ok(val) => val,
_ => return None,
},
};
let quantity = captures
.get(2)
.and_then(|v| v.as_str().parse::<u64>().ok())?;
let multiplier = match &captures.get(3).map_or("b", |m| m.as_str()).to_lowercase()[..] {
v if v.starts_with("ki") => KIBI,