From 503c50b1ec477e8aecc77b6f474f893ef7b6930b Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Mon, 18 Aug 2025 20:06:01 -0400 Subject: [PATCH] chore: address all `cargo clippy` lints * also do a bit of a doc cleanup for the `load_from_folder` fn --- src/assets.rs | 19 +++++++++++-------- src/assets/assets_metadata.rs | 18 +++++++++--------- src/bin/bat/app.rs | 4 ++-- src/bin/bat/input.rs | 2 +- src/input.rs | 2 +- src/printer.rs | 2 +- 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/assets.rs b/src/assets.rs index bc8ae16c..82c160c9 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -152,7 +152,7 @@ impl HighlightingAssets { &self, path: impl AsRef, mapping: &SyntaxMapping, - ) -> Result { + ) -> Result> { let path = path.as_ref(); let syntax_match = mapping.get_syntax_for(path); @@ -212,7 +212,7 @@ impl HighlightingAssets { language: Option<&str>, input: &mut OpenedInput, mapping: &SyntaxMapping, - ) -> Result { + ) -> Result> { if let Some(language) = language { let syntax_set = self.get_syntax_set()?; return syntax_set @@ -244,14 +244,17 @@ impl HighlightingAssets { pub(crate) fn find_syntax_by_name( &self, syntax_name: &str, - ) -> Result> { + ) -> Result>> { let syntax_set = self.get_syntax_set()?; Ok(syntax_set .find_syntax_by_name(syntax_name) .map(|syntax| SyntaxReferenceInSet { syntax, syntax_set })) } - fn find_syntax_by_extension(&self, e: Option<&OsStr>) -> Result> { + fn find_syntax_by_extension( + &self, + e: Option<&OsStr>, + ) -> Result>> { let syntax_set = self.get_syntax_set()?; let extension = e.and_then(|x| x.to_str()).unwrap_or_default(); Ok(syntax_set @@ -259,7 +262,7 @@ impl HighlightingAssets { .map(|syntax| SyntaxReferenceInSet { syntax, syntax_set })) } - fn find_syntax_by_token(&self, token: &str) -> Result> { + fn find_syntax_by_token(&self, token: &str) -> Result>> { let syntax_set = self.get_syntax_set()?; Ok(syntax_set .find_syntax_by_token(token) @@ -270,7 +273,7 @@ impl HighlightingAssets { &self, file_name: &OsStr, ignored_suffixes: &IgnoredSuffixes, - ) -> Result> { + ) -> Result>> { let mut syntax = self.find_syntax_by_extension(Some(file_name))?; if syntax.is_none() { syntax = @@ -286,7 +289,7 @@ impl HighlightingAssets { &self, file_name: &OsStr, ignored_suffixes: &IgnoredSuffixes, - ) -> Result> { + ) -> Result>> { let mut syntax = self.find_syntax_by_extension(Path::new(file_name).extension())?; if syntax.is_none() { syntax = @@ -301,7 +304,7 @@ impl HighlightingAssets { fn get_first_line_syntax( &self, reader: &mut InputReader, - ) -> Result> { + ) -> Result>> { let syntax_set = self.get_syntax_set()?; Ok(String::from_utf8(reader.first_line.clone()) .ok() diff --git a/src/assets/assets_metadata.rs b/src/assets/assets_metadata.rs index cfc7a9e0..63b0531a 100644 --- a/src/assets/assets_metadata.rs +++ b/src/assets/assets_metadata.rs @@ -40,15 +40,15 @@ impl AssetsMetadata { /// Load metadata about the stored cache file from the given folder. /// /// There are several possibilities: - /// - We find a metadata.yaml file and are able to parse it - /// => return the contained information - /// - We find a metadata.yaml file and but are not able to parse it - /// => return a SerdeYamlError - /// - We do not find a metadata.yaml file but a syntaxes.bin or themes.bin file - /// => assume that these were created by an old version of bat and return - /// AssetsMetadata::default() without version information - /// - We do not find a metadata.yaml file and no cached assets - /// => no user provided assets are available, return None + /// - We find a `metadata.yaml` file and are able to parse it + /// - return the contained information + /// - We find a `metadata.yaml` file, but are not able to parse it + /// - return a [`Error::SerdeYamlError`] + /// - We do not find a `metadata.yaml` file but a `syntaxes.bin` or `themes.bin` file + /// - assume that these were created by an old version of bat and return + /// [`AssetsMetadata::default()`] without version information + /// - We do not find a `metadata.yaml` file and no cached assets + /// - no user provided assets are available, return `None` pub fn load_from_folder(path: &Path) -> Result> { match Self::try_load_from_folder(path) { Ok(metadata) => Ok(Some(metadata)), diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 0474e120..b3d48cba 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -96,7 +96,7 @@ impl App { Ok(clap_app::build_app(interactive_output).get_matches_from(args)) } - pub fn config(&self, inputs: &[Input]) -> Result { + pub fn config(&self, inputs: &[Input]) -> Result> { let style_components = self.style_components()?; let extra_plain = self.matches.get_count("plain") > 1; @@ -338,7 +338,7 @@ impl App { }) } - pub fn inputs(&self) -> Result> { + pub fn inputs(&self) -> Result>> { let filenames: Option> = self .matches .get_many::("file-name") diff --git a/src/bin/bat/input.rs b/src/bin/bat/input.rs index 3c928906..a64001f2 100644 --- a/src/bin/bat/input.rs +++ b/src/bin/bat/input.rs @@ -5,7 +5,7 @@ pub fn new_file_input<'a>(file: &'a Path, name: Option<&'a Path>) -> Input<'a> { named(Input::ordinary_file(file), name.or(Some(file))) } -pub fn new_stdin_input(name: Option<&Path>) -> Input { +pub fn new_stdin_input(name: Option<&Path>) -> Input<'_> { named(Input::stdin(), name) } diff --git a/src/input.rs b/src/input.rs index 880d095e..f807d125 100644 --- a/src/input.rs +++ b/src/input.rs @@ -320,7 +320,7 @@ fn read_utf16_line( } // end of line not found, keep going } - return Ok(!buf.is_empty()); + Ok(!buf.is_empty()) } #[test] diff --git a/src/printer.rs b/src/printer.rs index 5b68e18e..665871b4 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -399,7 +399,7 @@ impl<'a> InteractivePrinter<'a> { while content_graphemes.len() > content_width { let (content_line, remaining) = content_graphemes.split_at(content_width); self.print_header_component_with_indent(handle, content_line.join("").as_str())?; - content_graphemes = remaining.iter().cloned().collect(); + content_graphemes = remaining.to_vec(); } self.print_header_component_with_indent(handle, content_graphemes.join("").as_str()) }