Skip to content

Commit

Permalink
style: prefer string interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
KSXGitHub committed Nov 24, 2024
1 parent ce88bd4 commit a463576
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 74 deletions.
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,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(())
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/os_string_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}")
}
}
}
2 changes: 1 addition & 1 deletion src/reporter/progress_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<Size: size::Size + Into<u64>> ProgressReport<Size> {
)
.unwrap();
if errors != 0 {
write!(text, ", erred {}", errors).unwrap();
write!(text, ", erred {errors}").unwrap();
}
write!(text, ")").unwrap();
GLOBAL_STATUS_BOARD.temporary_message(&text);
Expand Down
6 changes: 3 additions & 3 deletions src/status_board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
}
2 changes: 1 addition & 1 deletion src/visualizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/visualizer/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/visualizer/methods/initial_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions tests/_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
}
}
Expand Down Expand Up @@ -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))
};

Expand Down Expand Up @@ -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");
}
}
8 changes: 4 additions & 4 deletions tests/cli_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(),
Expand All @@ -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);
}
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
Loading

0 comments on commit a463576

Please sign in to comment.