diff --git a/src/app.rs b/src/app.rs index 9dfc86c..b00e1f9 100644 --- a/src/app.rs +++ b/src/app.rs @@ -88,7 +88,7 @@ impl App { UnitAndTree::Blocks(reflection) => visualize!(reflection, ()), }; - print!("{}", visualization); // it already ends with "\n", println! isn't needed here. + print!("{visualization}"); // it already ends with "\n", println! isn't needed here. return Ok(()); } diff --git a/src/app/sub.rs b/src/app/sub.rs index 8fe17e3..e7739de 100644 --- a/src/app/sub.rs +++ b/src/app/sub.rs @@ -159,7 +159,7 @@ where max_depth, }; - print!("{}", visualizer); // visualizer already ends with "\n", println! isn't needed here. + print!("{visualizer}"); // visualizer already ends with "\n", println! isn't needed here. Ok(()) } } diff --git a/src/lib.rs b/src/lib.rs index fed11c1..75ddf64 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ pub mod runtime_error; #[cfg(feature = "cli")] pub fn main() -> std::process::ExitCode { if let Err(error) = app::App::from_env().run() { - eprintln!("[error] {}", error); + eprintln!("[error] {error}"); return std::process::ExitCode::FAILURE; } std::process::ExitCode::SUCCESS diff --git a/src/os_string_display.rs b/src/os_string_display.rs index e7e33b8..e713aff 100644 --- a/src/os_string_display.rs +++ b/src/os_string_display.rs @@ -73,9 +73,9 @@ where fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error> { let inner = self.as_os_str(); if let Some(utf8) = inner.to_str() { - write!(formatter, "{}", utf8) + write!(formatter, "{utf8}") } else { - write!(formatter, "{:?}", inner) + write!(formatter, "{inner:?}") } } } diff --git a/src/reporter/progress_report.rs b/src/reporter/progress_report.rs index def67ba..e0466f8 100644 --- a/src/reporter/progress_report.rs +++ b/src/reporter/progress_report.rs @@ -29,7 +29,7 @@ impl> ProgressReport { ) .unwrap(); if errors != 0 { - write!(text, ", erred {}", errors).unwrap(); + write!(text, ", erred {errors}").unwrap(); } write!(text, ")").unwrap(); GLOBAL_STATUS_BOARD.temporary_message(&text); diff --git a/src/status_board.rs b/src/status_board.rs index eb72885..110a578 100644 --- a/src/status_board.rs +++ b/src/status_board.rs @@ -32,19 +32,19 @@ impl StatusBoard { /// Clear the line that the cursor is pointing to. pub fn clear_line(&self, new_line_width: usize) { let empty_line = repeat(' ', self.get_line_width()); - eprint!("\r{}\r", empty_line); + eprint!("\r{empty_line}\r"); self.set_line_width(new_line_width); } /// Show a temporary message. pub fn temporary_message(&self, message: &str) { self.clear_line(message.width()); - eprint!("{}", message); + eprint!("{message}"); } /// Log a permanent message. pub fn permanent_message(&self, message: &str) { self.clear_line(0); - eprintln!("{}", message); + eprintln!("{message}"); } } diff --git a/src/visualizer.rs b/src/visualizer.rs index c5d6c7b..9db3395 100644 --- a/src/visualizer.rs +++ b/src/visualizer.rs @@ -40,7 +40,7 @@ use std::{fmt::Display, num::NonZeroUsize}; /// column_width_distribution: ColumnWidthDistribution::total(100), /// max_depth: std::num::NonZeroUsize::new(10).unwrap(), /// }; -/// println!("{}", visualizer); +/// println!("{visualizer}"); /// # } /// ``` #[derive(Debug)] diff --git a/src/visualizer/display.rs b/src/visualizer/display.rs index 389093c..1b3f513 100644 --- a/src/visualizer/display.rs +++ b/src/visualizer/display.rs @@ -9,7 +9,7 @@ where { /// Create the ASCII chart. fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error> { - let write = |line: &String| writeln!(formatter, "{}", line); + let write = |line: &String| writeln!(formatter, "{line}"); match self.direction { BottomUp => self.rows().iter().rev().try_for_each(write), TopDown => self.rows().iter().try_for_each(write), diff --git a/src/visualizer/methods/initial_table.rs b/src/visualizer/methods/initial_table.rs index 84c42fd..0a70482 100644 --- a/src/visualizer/methods/initial_table.rs +++ b/src/visualizer/methods/initial_table.rs @@ -120,7 +120,7 @@ where "0%".to_string() } else { let percentage = rounded_div::u64(fs_size * 100, total_fs_size); - format!("{}%", percentage) + format!("{percentage}%") }; let size = node.size().display(visualizer.bytes_format).to_string(); let sibling_count = ancestors.last().map_or(1, |parent| parent.children_count); diff --git a/tests/_utils.rs b/tests/_utils.rs index 6a56758..19bf6d6 100644 --- a/tests/_utils.rs +++ b/tests/_utils.rs @@ -58,7 +58,7 @@ impl Drop for Temp { fn drop(&mut self) { let path = &self.0; if let Err(error) = remove_dir_all(path) { - eprintln!("warning: Failed to delete {:?}: {}", path, error); + eprintln!("warning: Failed to delete {path:?}: {error}"); } } } @@ -133,7 +133,7 @@ where let suffix_size = |suffix: &str| -> Size { root.join(suffix) .pipe(metadata) - .unwrap_or_else(|error| panic!("get_size {}: {}", suffix, error)) + .unwrap_or_else(|error| panic!("get_size {suffix}: {error}")) .pipe(|ref metadata| size_getter.get_size(metadata)) }; @@ -327,6 +327,6 @@ pub fn inspect_stderr(stderr: &[u8]) { let text = String::from_utf8_lossy(stderr); let text = text.trim(); if !text.is_empty() { - eprintln!("STDERR:\n{}\n", text); + eprintln!("STDERR:\n{text}\n"); } } diff --git a/tests/cli_errors.rs b/tests/cli_errors.rs index 0c16604..35fd25a 100644 --- a/tests/cli_errors.rs +++ b/tests/cli_errors.rs @@ -62,7 +62,7 @@ fn min_ratio_1() { let stderr = String::from_utf8(stderr).expect("parse stderr as UTF-8"); let stderr = stderr.trim_end(); dbg!(&status); - eprintln!("STDERR:\n{}\n", stderr); + eprintln!("STDERR:\n{stderr}\n"); assert!(!status.success()); assert_eq!( stderr, @@ -91,7 +91,7 @@ fn max_depth_0() { let stderr = String::from_utf8(stderr).expect("parse stderr as UTF-8"); let stderr = stderr.trim_end(); dbg!(&status); - eprintln!("STDERR:\n{}\n", stderr); + eprintln!("STDERR:\n{stderr}\n"); assert!(!status.success()); assert_eq!( stderr, @@ -127,7 +127,7 @@ fn fs_errors() { let stderr = String::from_utf8(stderr).expect("parse stderr as UTF-8"); let stdout = String::from_utf8(stdout).expect("parse stdout as UTF-8"); dbg!(&status); - eprintln!("STDERR+STDOUT:\n{}{}\n", &stderr, &stdout); + eprintln!("STDERR+STDOUT:\n{stderr}{stdout}\n"); let builder = FsTreeBuilder { root: workspace.to_path_buf(), @@ -145,7 +145,7 @@ fn fs_errors() { column_width_distribution: ColumnWidthDistribution::total(100), max_depth: 10.try_into().unwrap(), }; - let expected_stdout = format!("{}", visualizer); + let expected_stdout = format!("{visualizer}"); eprintln!("EXPECTED STDOUT:\n{}\n", &expected_stdout); fs_permission(&workspace, "+rwx", true); // to allow SampleWorkspace destructor to clean itself diff --git a/tests/json.rs b/tests/json.rs index 29c3747..35a0a5e 100644 --- a/tests/json.rs +++ b/tests/json.rs @@ -101,7 +101,7 @@ fn json_input() { unit_and_tree: sample_tree().into_reflection().into(), }; let json = serde_json::to_string_pretty(&json_data).expect("convert sample tree to JSON"); - eprintln!("JSON: {}\n", json); + eprintln!("JSON: {json}\n"); let workspace = Temp::new_dir().expect("create temporary directory"); let mut child = Command::new(PDU) .with_current_dir(&workspace) @@ -125,7 +125,7 @@ fn json_input() { .expect("wait for output of child process") .pipe(stdout_text); let actual = actual.trim_end(); - eprintln!("ACTUAL:\n{}\n", &actual); + eprintln!("ACTUAL:\n{actual}\n"); let visualizer = Visualizer { data_tree: &sample_tree(), @@ -135,9 +135,9 @@ fn json_input() { column_width_distribution: ColumnWidthDistribution::total(100), max_depth: 10.try_into().unwrap(), }; - let expected = format!("{}", visualizer); + let expected = format!("{visualizer}"); let expected = expected.trim_end(); - eprintln!("EXPECTED:\n{}\n", expected); + eprintln!("EXPECTED:\n{expected}\n"); assert_eq!(actual, expected); } @@ -173,7 +173,7 @@ fn json_output_json_input() { .output() .expect("spawn command with --json-input") .pipe(stdout_text); - eprintln!("ACTUAL:\n{}\n", &actual); + eprintln!("ACTUAL:\n{actual}\n"); let expected = Command::new(PDU) .with_current_dir(&workspace) @@ -188,7 +188,7 @@ fn json_output_json_input() { .output() .expect("spawn command for expected") .pipe(stdout_text); - eprintln!("EXPECTED:\n{}\n", expected); + eprintln!("EXPECTED:\n{expected}\n"); assert_eq!(actual, expected); } diff --git a/tests/usual_cli.rs b/tests/usual_cli.rs index 71cf2ba..4cd6a26 100644 --- a/tests/usual_cli.rs +++ b/tests/usual_cli.rs @@ -37,7 +37,7 @@ fn total_width() { .output() .expect("spawn command") .pipe(stdout_text); - eprintln!("ACTUAL:\n{}\n", &actual); + eprintln!("ACTUAL:\n{actual}\n"); let builder = FsTreeBuilder { root: workspace.to_path_buf(), @@ -56,9 +56,9 @@ fn total_width() { column_width_distribution: ColumnWidthDistribution::total(100), max_depth: 10.try_into().unwrap(), }; - let expected = format!("{}", visualizer); + let expected = format!("{visualizer}"); let expected = expected.trim_end(); - eprintln!("EXPECTED:\n{}\n", expected); + eprintln!("EXPECTED:\n{expected}\n"); assert_eq!(actual, expected); } @@ -75,7 +75,7 @@ fn column_width() { .output() .expect("spawn command") .pipe(stdout_text); - eprintln!("ACTUAL:\n{}\n", &actual); + eprintln!("ACTUAL:\n{actual}\n"); let builder = FsTreeBuilder { root: workspace.to_path_buf(), @@ -94,9 +94,9 @@ fn column_width() { column_width_distribution: ColumnWidthDistribution::components(10, 90), max_depth: 10.try_into().unwrap(), }; - let expected = format!("{}", visualizer); + let expected = format!("{visualizer}"); let expected = expected.trim_end(); - eprintln!("EXPECTED:\n{}\n", expected); + eprintln!("EXPECTED:\n{expected}\n"); assert_eq!(actual, expected); } @@ -113,7 +113,7 @@ fn min_ratio_0() { .output() .expect("spawn command") .pipe(stdout_text); - eprintln!("ACTUAL:\n{}\n", &actual); + eprintln!("ACTUAL:\n{actual}\n"); let builder = FsTreeBuilder { root: workspace.to_path_buf(), @@ -131,9 +131,9 @@ fn min_ratio_0() { column_width_distribution: ColumnWidthDistribution::total(100), max_depth: 10.try_into().unwrap(), }; - let expected = format!("{}", visualizer); + let expected = format!("{visualizer}"); let expected = expected.trim_end(); - eprintln!("EXPECTED:\n{}\n", expected); + eprintln!("EXPECTED:\n{expected}\n"); assert_eq!(actual, expected); } @@ -150,7 +150,7 @@ fn min_ratio() { .output() .expect("spawn command") .pipe(stdout_text); - eprintln!("ACTUAL:\n{}\n", &actual); + eprintln!("ACTUAL:\n{actual}\n"); let builder = FsTreeBuilder { root: workspace.to_path_buf(), @@ -169,9 +169,9 @@ fn min_ratio() { column_width_distribution: ColumnWidthDistribution::total(100), max_depth: 10.try_into().unwrap(), }; - let expected = format!("{}", visualizer); + let expected = format!("{visualizer}"); let expected = expected.trim_end(); - eprintln!("EXPECTED:\n{}\n", expected); + eprintln!("EXPECTED:\n{expected}\n"); assert_eq!(actual, expected); } @@ -188,7 +188,7 @@ fn max_depth_2() { .output() .expect("spawn command") .pipe(stdout_text); - eprintln!("ACTUAL:\n{}\n", &actual); + eprintln!("ACTUAL:\n{actual}\n"); let builder = FsTreeBuilder { root: workspace.to_path_buf(), @@ -207,9 +207,9 @@ fn max_depth_2() { column_width_distribution: ColumnWidthDistribution::total(100), max_depth: 2.try_into().unwrap(), }; - let expected = format!("{}", visualizer); + let expected = format!("{visualizer}"); let expected = expected.trim_end(); - eprintln!("EXPECTED:\n{}\n", expected); + eprintln!("EXPECTED:\n{expected}\n"); assert_eq!(actual, expected); } @@ -226,7 +226,7 @@ fn max_depth_1() { .output() .expect("spawn command") .pipe(stdout_text); - eprintln!("ACTUAL:\n{}\n", &actual); + eprintln!("ACTUAL:\n{actual}\n"); let builder = FsTreeBuilder { root: workspace.to_path_buf(), @@ -245,9 +245,9 @@ fn max_depth_1() { column_width_distribution: ColumnWidthDistribution::total(100), max_depth: 1.try_into().unwrap(), }; - let expected = format!("{}", visualizer); + let expected = format!("{visualizer}"); let expected = expected.trim_end(); - eprintln!("EXPECTED:\n{}\n", expected); + eprintln!("EXPECTED:\n{expected}\n"); assert_eq!(actual, expected); } @@ -263,7 +263,7 @@ fn top_down() { .output() .expect("spawn command") .pipe(stdout_text); - eprintln!("ACTUAL:\n{}\n", &actual); + eprintln!("ACTUAL:\n{actual}\n"); let builder = FsTreeBuilder { root: workspace.to_path_buf(), @@ -282,9 +282,9 @@ fn top_down() { column_width_distribution: ColumnWidthDistribution::total(100), max_depth: 10.try_into().unwrap(), }; - let expected = format!("{}", visualizer); + let expected = format!("{visualizer}"); let expected = expected.trim_end(); - eprintln!("EXPECTED:\n{}\n", expected); + eprintln!("EXPECTED:\n{expected}\n"); assert_eq!(actual, expected); } @@ -300,7 +300,7 @@ fn align_right() { .output() .expect("spawn command") .pipe(stdout_text); - eprintln!("ACTUAL:\n{}\n", &actual); + eprintln!("ACTUAL:\n{actual}\n"); let builder = FsTreeBuilder { root: workspace.to_path_buf(), @@ -319,9 +319,9 @@ fn align_right() { column_width_distribution: ColumnWidthDistribution::total(100), max_depth: 10.try_into().unwrap(), }; - let expected = format!("{}", visualizer); + let expected = format!("{visualizer}"); let expected = expected.trim_end(); - eprintln!("EXPECTED:\n{}\n", expected); + eprintln!("EXPECTED:\n{expected}\n"); assert_eq!(actual, expected); } @@ -337,7 +337,7 @@ fn quantity_apparent_size() { .output() .expect("spawn command") .pipe(stdout_text); - eprintln!("ACTUAL:\n{}\n", &actual); + eprintln!("ACTUAL:\n{actual}\n"); let builder = FsTreeBuilder { root: workspace.to_path_buf(), @@ -356,9 +356,9 @@ fn quantity_apparent_size() { column_width_distribution: ColumnWidthDistribution::total(100), max_depth: 10.try_into().unwrap(), }; - let expected = format!("{}", visualizer); + let expected = format!("{visualizer}"); let expected = expected.trim_end(); - eprintln!("EXPECTED:\n{}\n", expected); + eprintln!("EXPECTED:\n{expected}\n"); assert_eq!(actual, expected); } @@ -375,7 +375,7 @@ fn quantity_block_size() { .output() .expect("spawn command") .pipe(stdout_text); - eprintln!("ACTUAL:\n{}\n", &actual); + eprintln!("ACTUAL:\n{actual}\n"); let builder = FsTreeBuilder { root: workspace.to_path_buf(), @@ -394,9 +394,9 @@ fn quantity_block_size() { column_width_distribution: ColumnWidthDistribution::total(100), max_depth: 10.try_into().unwrap(), }; - let expected = format!("{}", visualizer); + let expected = format!("{visualizer}"); let expected = expected.trim_end(); - eprintln!("EXPECTED:\n{}\n", expected); + eprintln!("EXPECTED:\n{expected}\n"); assert_eq!(actual, expected); } @@ -413,7 +413,7 @@ fn quantity_block_count() { .output() .expect("spawn command") .pipe(stdout_text); - eprintln!("ACTUAL:\n{}\n", &actual); + eprintln!("ACTUAL:\n{actual}\n"); let builder = FsTreeBuilder { root: workspace.to_path_buf(), @@ -432,9 +432,9 @@ fn quantity_block_count() { column_width_distribution: ColumnWidthDistribution::total(100), max_depth: 10.try_into().unwrap(), }; - let expected = format!("{}", visualizer); + let expected = format!("{visualizer}"); let expected = expected.trim_end(); - eprintln!("EXPECTED:\n{}\n", expected); + eprintln!("EXPECTED:\n{expected}\n"); assert_eq!(actual, expected); } @@ -452,7 +452,7 @@ fn bytes_format_plain() { .output() .expect("spawn command") .pipe(stdout_text); - eprintln!("ACTUAL:\n{}\n", &actual); + eprintln!("ACTUAL:\n{actual}\n"); let builder = FsTreeBuilder { root: workspace.to_path_buf(), @@ -471,9 +471,9 @@ fn bytes_format_plain() { column_width_distribution: ColumnWidthDistribution::total(100), max_depth: 10.try_into().unwrap(), }; - let expected = format!("{}", visualizer); + let expected = format!("{visualizer}"); let expected = expected.trim_end(); - eprintln!("EXPECTED:\n{}\n", expected); + eprintln!("EXPECTED:\n{expected}\n"); assert_eq!(actual, expected); } @@ -491,7 +491,7 @@ fn bytes_format_metric() { .output() .expect("spawn command") .pipe(stdout_text); - eprintln!("ACTUAL:\n{}\n", &actual); + eprintln!("ACTUAL:\n{actual}\n"); let builder = FsTreeBuilder { root: workspace.to_path_buf(), @@ -510,9 +510,9 @@ fn bytes_format_metric() { column_width_distribution: ColumnWidthDistribution::total(100), max_depth: 10.try_into().unwrap(), }; - let expected = format!("{}", visualizer); + let expected = format!("{visualizer}"); let expected = expected.trim_end(); - eprintln!("EXPECTED:\n{}\n", expected); + eprintln!("EXPECTED:\n{expected}\n"); assert_eq!(actual, expected); } @@ -530,7 +530,7 @@ fn bytes_format_binary() { .output() .expect("spawn command") .pipe(stdout_text); - eprintln!("ACTUAL:\n{}\n", &actual); + eprintln!("ACTUAL:\n{actual}\n"); let builder = FsTreeBuilder { root: workspace.to_path_buf(), @@ -549,9 +549,9 @@ fn bytes_format_binary() { column_width_distribution: ColumnWidthDistribution::total(100), max_depth: 10.try_into().unwrap(), }; - let expected = format!("{}", visualizer); + let expected = format!("{visualizer}"); let expected = expected.trim_end(); - eprintln!("EXPECTED:\n{}\n", expected); + eprintln!("EXPECTED:\n{expected}\n"); assert_eq!(actual, expected); } @@ -567,7 +567,7 @@ fn path_to_workspace() { .output() .expect("spawn command") .pipe(stdout_text); - eprintln!("ACTUAL:\n{}\n", &actual); + eprintln!("ACTUAL:\n{actual}\n"); let builder = FsTreeBuilder { root: workspace.to_path_buf(), @@ -585,9 +585,9 @@ fn path_to_workspace() { column_width_distribution: ColumnWidthDistribution::total(100), max_depth: 10.try_into().unwrap(), }; - let expected = format!("{}", visualizer); + let expected = format!("{visualizer}"); let expected = expected.trim_end(); - eprintln!("EXPECTED:\n{}\n", expected); + eprintln!("EXPECTED:\n{expected}\n"); assert_eq!(actual, expected); } @@ -606,7 +606,7 @@ fn multiple_names() { .output() .expect("spawn command") .pipe(stdout_text); - eprintln!("ACTUAL:\n{}\n", &actual); + eprintln!("ACTUAL:\n{actual}\n"); let mut data_tree = ["nested", "flat", "empty-dir"] .iter() @@ -637,9 +637,9 @@ fn multiple_names() { column_width_distribution: ColumnWidthDistribution::total(100), max_depth: 10.try_into().unwrap(), }; - let expected = format!("{}", visualizer); + let expected = format!("{visualizer}"); let expected = expected.trim_end(); - eprintln!("EXPECTED:\n{}\n", expected); + eprintln!("EXPECTED:\n{expected}\n"); assert_eq!(actual, expected); } diff --git a/tests/visualizer.rs b/tests/visualizer.rs index 936f1e3..e693f28 100644 --- a/tests/visualizer.rs +++ b/tests/visualizer.rs @@ -47,7 +47,7 @@ macro_rules! test_case { } .to_string(); let expected = $expected; - eprintln!("\nACTUAL:\n{}\n", &actual); + eprintln!("\nACTUAL:\n{actual}\n"); let actual_lines: Vec<_> = actual.lines().collect(); let expected_lines: Vec<_> = expected.lines().collect();