summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2022-09-19 08:58:15 +0800
committerSebastian Thiel <sebastian.thiel@icloud.com>2022-09-19 08:58:15 +0800
commita734efb7e332de6a3bb4911e72463e4f6fc342e1 (patch)
treeaa674af2770977221bf9dfb122dc5458c99ff21d
parent44e19ee67924eb28b87698874d377a999cafceee (diff)
refactor
-rw-r--r--src/aggregate.rs23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/aggregate.rs b/src/aggregate.rs
index 0409634..2a4fb01 100644
--- a/src/aggregate.rs
+++ b/src/aggregate.rs
@@ -186,11 +186,7 @@ pub fn aggregate(
}
fn path_color_of(path: impl AsRef<Path>) -> Option<Color> {
- if path.as_ref().is_file() {
- None
- } else {
- Some(Color::Cyan)
- }
+ (!path.as_ref().is_file()).then(|| Color::Cyan)
}
fn output_colored_path(
@@ -204,20 +200,19 @@ fn output_colored_path(
let size = options.byte_format.display(num_bytes).to_string();
let size = size.green();
let size_width = options.byte_format.width();
-
let path = path.as_ref().display();
- let errors = if let 0 = num_errors {
- String::new()
- } else {
- let s = if num_errors > 1 { "s" } else { "" };
- format!(" <{num_errors} IO Error{s}>")
- };
+ let errors = (num_errors != 0)
+ .then(|| {
+ let plural_s = if num_errors > 1 { "s" } else { "" };
+ format!(" <{num_errors} IO Error{plural_s}>")
+ })
+ .unwrap_or_default();
if let Some(color) = path_color {
- writeln!(out, "{size:>size_width$} {}{errors}", path.color(color),)
+ writeln!(out, "{size:>size_width$} {}{errors}", path.color(color))
} else {
- writeln!(out, "{size:>size_width$} {path}{errors}",)
+ writeln!(out, "{size:>size_width$} {path}{errors}")
}
}