diff options
author | Lena <126529524+acuteenvy@users.noreply.github.com> | 2024-02-24 22:36:14 +0100 |
---|---|---|
committer | Martin Nordholts <enselic@gmail.com> | 2024-02-25 00:38:11 +0100 |
commit | 4c85483486172a706ab7fe7a5a7c7c4e6b8ebf3b (patch) | |
tree | d314a7e6ed70fe8585e624977faffb14012daafa /src | |
parent | 487bed2d953424fd30dd125082a3bf26600aa180 (diff) |
Inline `format!` args wherever possible
Diffstat (limited to 'src')
-rw-r--r-- | src/assets.rs | 9 | ||||
-rw-r--r-- | src/assets/build_assets.rs | 4 | ||||
-rw-r--r-- | src/assets/build_assets/acknowledgements.rs | 4 | ||||
-rw-r--r-- | src/assets/lazy_theme_set.rs | 2 | ||||
-rw-r--r-- | src/bin/bat/assets.rs | 2 | ||||
-rw-r--r-- | src/bin/bat/clap_app.rs | 2 | ||||
-rw-r--r-- | src/bin/bat/main.rs | 7 | ||||
-rw-r--r-- | src/decorations.rs | 2 | ||||
-rw-r--r-- | src/input.rs | 2 | ||||
-rw-r--r-- | src/printer.rs | 10 | ||||
-rw-r--r-- | src/style.rs | 2 | ||||
-rw-r--r-- | src/syntax_mapping/ignored_suffixes.rs | 4 | ||||
-rw-r--r-- | src/vscreen.rs | 6 |
13 files changed, 26 insertions, 30 deletions
diff --git a/src/assets.rs b/src/assets.rs index 0129f76b..9655553d 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -380,7 +380,7 @@ fn asset_from_contents<T: serde::de::DeserializeOwned>( } else { bincode::deserialize_from(contents) } - .map_err(|_| format!("Could not parse {}", description).into()) + .map_err(|_| format!("Could not parse {description}").into()) } fn asset_from_cache<T: serde::de::DeserializeOwned>( @@ -396,7 +396,7 @@ fn asset_from_cache<T: serde::de::DeserializeOwned>( ) })?; asset_from_contents(&contents[..], description, compressed) - .map_err(|_| format!("Could not parse cached {}", description).into()) + .map_err(|_| format!("Could not parse cached {description}").into()) } #[cfg(target_os = "macos")] @@ -466,7 +466,7 @@ mod tests { let file_path = self.temp_dir.path().join(file_name); { let mut temp_file = File::create(&file_path).unwrap(); - writeln!(temp_file, "{}", first_line).unwrap(); + writeln!(temp_file, "{first_line}").unwrap(); } let input = Input::ordinary_file(&file_path); @@ -514,8 +514,7 @@ mod tests { if !consistent { eprintln!( - "Inconsistent syntax detection:\nFor File: {}\nFor Reader: {}", - as_file, as_reader + "Inconsistent syntax detection:\nFor File: {as_file}\nFor Reader: {as_reader}" ) } diff --git a/src/assets/build_assets.rs b/src/assets/build_assets.rs index f3448679..5406c2f7 100644 --- a/src/assets/build_assets.rs +++ b/src/assets/build_assets.rs @@ -93,7 +93,7 @@ fn print_unlinked_contexts(syntax_set: &SyntaxSet) { if !missing_contexts.is_empty() { println!("Some referenced contexts could not be found!"); for context in missing_contexts { - println!("- {}", context); + println!("- {context}"); } } } @@ -152,7 +152,7 @@ pub(crate) fn asset_to_contents<T: serde::Serialize>( } else { bincode::serialize_into(&mut contents, asset) } - .map_err(|_| format!("Could not serialize {}", description))?; + .map_err(|_| format!("Could not serialize {description}"))?; Ok(contents) } diff --git a/src/assets/build_assets/acknowledgements.rs b/src/assets/build_assets/acknowledgements.rs index fc915548..c4fde919 100644 --- a/src/assets/build_assets/acknowledgements.rs +++ b/src/assets/build_assets/acknowledgements.rs @@ -80,7 +80,7 @@ fn handle_license(path: &Path) -> Result<Option<String>> { } else if license_not_needed_in_acknowledgements(&license_text) { Ok(None) } else { - Err(format!("ERROR: License is of unknown type: {:?}", path).into()) + Err(format!("ERROR: License is of unknown type: {path:?}").into()) } } @@ -125,7 +125,7 @@ fn append_to_acknowledgements( relative_path: &str, license_text: &str, ) { - write!(acknowledgements, "## {}\n\n{}", relative_path, license_text).ok(); + write!(acknowledgements, "## {relative_path}\n\n{license_text}").ok(); // Make sure the last char is a newline to not mess up formatting later if acknowledgements diff --git a/src/assets/lazy_theme_set.rs b/src/assets/lazy_theme_set.rs index fcc3eb46..f3f3f690 100644 --- a/src/assets/lazy_theme_set.rs +++ b/src/assets/lazy_theme_set.rs @@ -88,7 +88,7 @@ impl TryFrom<ThemeSet> for LazyThemeSet { let lazy_theme = LazyTheme { serialized: crate::assets::build_assets::asset_to_contents( &theme, - &format!("theme {}", name), + &format!("theme {name}"), COMPRESS_LAZY_THEMES, )?, deserialized: OnceCell::new(), diff --git a/src/bin/bat/assets.rs b/src/bin/bat/assets.rs index a54927b8..0eeb5bf1 100644 --- a/src/bin/bat/assets.rs +++ b/src/bin/bat/assets.rs @@ -44,7 +44,7 @@ pub fn assets_from_cache_or_binary( } fn clear_asset(path: PathBuf, description: &str) { - print!("Clearing {} ... ", description); + print!("Clearing {description} ... "); match fs::remove_file(&path) { Err(err) if err.kind() == io::ErrorKind::NotFound => { println!("skipped (not present)"); diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index ac7f5c18..b82762b6 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -430,7 +430,7 @@ pub fn build_app(interactive_output: bool) -> Command { }); if let Some(invalid) = invalid_vals.next() { - Err(format!("Unknown style, '{}'", invalid)) + Err(format!("Unknown style, '{invalid}'")) } else { Ok(val.to_owned()) } diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index d877bb9b..38595721 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -222,7 +222,7 @@ pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result< )?; } else { for theme in assets.themes() { - writeln!(stdout, "{}", theme)?; + writeln!(stdout, "{theme}")?; } } @@ -232,10 +232,7 @@ pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result< fn set_terminal_title_to(new_terminal_title: String) { let osc_command_for_setting_terminal_title = "\x1b]0;"; let osc_end_command = "\x07"; - print!( - "{}{}{}", - osc_command_for_setting_terminal_title, new_terminal_title, osc_end_command - ); + print!("{osc_command_for_setting_terminal_title}{new_terminal_title}{osc_end_command}"); io::stdout().flush().unwrap(); } diff --git a/src/decorations.rs b/src/decorations.rs index 85d8103a..5b7846c3 100644 --- a/src/decorations.rs +++ b/src/decorations.rs @@ -56,7 +56,7 @@ impl Decoration for LineNumberDecoration { self.cached_wrap.clone() } else { - let plain: String = format!("{:4}", line_number); + let plain: String = format!("{line_number:4}"); DecorationText { width: plain.len(), text: self.color.paint(plain).to_string(), diff --git a/src/input.rs b/src/input.rs index ccab98bf..0ebaa4ce 100644 --- a/src/input.rs +++ b/src/input.rs @@ -197,7 +197,7 @@ impl<'a> Input<'a> { InputKind::StdIn => { if let Some(stdout) = stdout_identifier { let input_identifier = Identifier::try_from(clircle::Stdio::Stdin) - .map_err(|e| format!("Stdin: Error identifying file: {}", e))?; + .map_err(|e| format!("Stdin: Error identifying file: {e}"))?; if stdout.surely_conflicts_with(&input_identifier) { return Err("IO circle detected. The input from stdin is also an output. Aborting to avoid infinite loop.".into()); } diff --git a/src/printer.rs b/src/printer.rs index fc6c16f0..8dbe9d0b 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -160,7 +160,7 @@ impl<'a> Printer for SimplePrinter<'a> { self.config.tab_width, self.config.nonprintable_notation, ); - write!(handle, "{}", line)?; + write!(handle, "{line}")?; } else { match handle { OutputHandle::IoWrite(handle) => handle.write_all(line_buffer)?, @@ -333,7 +333,7 @@ impl<'a> InteractivePrinter<'a> { " ".repeat(self.panel_width - 1 - text_truncated.len()) ); if self.config.style_components.grid() { - format!("{} │ ", text_filled) + format!("{text_filled} │ ") } else { text_filled } @@ -368,7 +368,7 @@ impl<'a> InteractivePrinter<'a> { content: &str, ) -> Result<()> { self.print_header_component_indent(handle)?; - writeln!(handle, "{}", content) + writeln!(handle, "{content}") } fn print_header_multiline_component( @@ -494,7 +494,7 @@ impl<'a> Printer for InteractivePrinter<'a> { "{}{}{}", description .kind() - .map(|kind| format!("{}: ", kind)) + .map(|kind| format!("{kind}: ")) .unwrap_or_else(|| "".into()), self.colors.header_value.paint(description.title()), mode @@ -552,7 +552,7 @@ impl<'a> Printer for InteractivePrinter<'a> { "{}", self.colors .grid - .paint(format!("{}{}{}{}", panel, snip_left, title, snip_right)) + .paint(format!("{panel}{snip_left}{title}{snip_right}")) )?; Ok(()) diff --git a/src/style.rs b/src/style.rs index 0f83d1bc..652b3743 100644 --- a/src/style.rs +++ b/src/style.rs @@ -80,7 +80,7 @@ impl FromStr for StyleComponent { "full" => Ok(StyleComponent::Full), "default" => Ok(StyleComponent::Default), "plain" => Ok(StyleComponent::Plain), - _ => Err(format!("Unknown style '{}'", s).into()), + _ => Err(format!("Unknown style '{s}'").into()), } } } diff --git a/src/syntax_mapping/ignored_suffixes.rs b/src/syntax_mapping/ignored_suffixes.rs index 6ee7a598..a6d38e8f 100644 --- a/src/syntax_mapping/ignored_suffixes.rs +++ b/src/syntax_mapping/ignored_suffixes.rs @@ -73,7 +73,7 @@ fn internal_suffixes() { let file_names = ignored_suffixes .values .iter() - .map(|suffix| format!("test.json{}", suffix)); + .map(|suffix| format!("test.json{suffix}")); for file_name_str in file_names { let file_name = OsStr::new(&file_name_str); let expected_stripped_file_name = OsStr::new("test.json"); @@ -95,7 +95,7 @@ fn external_suffixes() { let file_names = ignored_suffixes .values .iter() - .map(|suffix| format!("test.json{}", suffix)); + .map(|suffix| format!("test.json{suffix}")); for file_name_str in file_names { let file_name = OsStr::new(&file_name_str); let expected_stripped_file_name = OsStr::new("test.json"); diff --git a/src/vscreen.rs b/src/vscreen.rs index f7ba3f91..e211c2aa 100644 --- a/src/vscreen.rs +++ b/src/vscreen.rs @@ -221,11 +221,11 @@ impl Attributes { 8 => match parameters.next() { Some(5) /* 256-color */ => format!("\x1B[{};5;{}m", color, join(";", 1, parameters)), Some(2) /* 24-bit color */ => format!("\x1B[{};2;{}m", color, join(";", 3, parameters)), - Some(c) => format!("\x1B[{};{}m", color, c), + Some(c) => format!("\x1B[{color};{c}m"), _ => "".to_owned(), }, 9 => "".to_owned(), - _ => format!("\x1B[{}m", color), + _ => format!("\x1B[{color}m"), } } @@ -435,7 +435,7 @@ impl<'a> EscapeSequenceOffsetsIterator<'a> { } Some((_, tc)) => { - panic!("this should not be reached: char {:?}", tc) + panic!("this should not be reached: char {tc:?}") } } } |