mirror of
				https://github.com/sharkdp/bat.git
				synced 2025-11-04 00:51:56 +00:00 
			
		
		
		
	chore: address all cargo clippy lints
				
					
				
			* also do a bit of a doc cleanup for the `load_from_folder` fn
This commit is contained in:
		
				
					committed by
					
						
						Martin Nordholts
					
				
			
			
				
	
			
			
			
						parent
						
							d9fbd18541
						
					
				
				
					commit
					503c50b1ec
				
			@@ -152,7 +152,7 @@ impl HighlightingAssets {
 | 
			
		||||
        &self,
 | 
			
		||||
        path: impl AsRef<Path>,
 | 
			
		||||
        mapping: &SyntaxMapping,
 | 
			
		||||
    ) -> Result<SyntaxReferenceInSet> {
 | 
			
		||||
    ) -> Result<SyntaxReferenceInSet<'_>> {
 | 
			
		||||
        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<SyntaxReferenceInSet> {
 | 
			
		||||
    ) -> Result<SyntaxReferenceInSet<'_>> {
 | 
			
		||||
        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<Option<SyntaxReferenceInSet>> {
 | 
			
		||||
    ) -> Result<Option<SyntaxReferenceInSet<'_>>> {
 | 
			
		||||
        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<Option<SyntaxReferenceInSet>> {
 | 
			
		||||
    fn find_syntax_by_extension(
 | 
			
		||||
        &self,
 | 
			
		||||
        e: Option<&OsStr>,
 | 
			
		||||
    ) -> Result<Option<SyntaxReferenceInSet<'_>>> {
 | 
			
		||||
        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<Option<SyntaxReferenceInSet>> {
 | 
			
		||||
    fn find_syntax_by_token(&self, token: &str) -> Result<Option<SyntaxReferenceInSet<'_>>> {
 | 
			
		||||
        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<Option<SyntaxReferenceInSet>> {
 | 
			
		||||
    ) -> Result<Option<SyntaxReferenceInSet<'_>>> {
 | 
			
		||||
        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<Option<SyntaxReferenceInSet>> {
 | 
			
		||||
    ) -> Result<Option<SyntaxReferenceInSet<'_>>> {
 | 
			
		||||
        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<Option<SyntaxReferenceInSet>> {
 | 
			
		||||
    ) -> Result<Option<SyntaxReferenceInSet<'_>>> {
 | 
			
		||||
        let syntax_set = self.get_syntax_set()?;
 | 
			
		||||
        Ok(String::from_utf8(reader.first_line.clone())
 | 
			
		||||
            .ok()
 | 
			
		||||
 
 | 
			
		||||
@@ -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<Option<Self>> {
 | 
			
		||||
        match Self::try_load_from_folder(path) {
 | 
			
		||||
            Ok(metadata) => Ok(Some(metadata)),
 | 
			
		||||
 
 | 
			
		||||
@@ -96,7 +96,7 @@ impl App {
 | 
			
		||||
        Ok(clap_app::build_app(interactive_output).get_matches_from(args))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn config(&self, inputs: &[Input]) -> Result<Config> {
 | 
			
		||||
    pub fn config(&self, inputs: &[Input]) -> Result<Config<'_>> {
 | 
			
		||||
        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<Vec<Input>> {
 | 
			
		||||
    pub fn inputs(&self) -> Result<Vec<Input<'_>>> {
 | 
			
		||||
        let filenames: Option<Vec<&Path>> = self
 | 
			
		||||
            .matches
 | 
			
		||||
            .get_many::<PathBuf>("file-name")
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -320,7 +320,7 @@ fn read_utf16_line<R: BufRead>(
 | 
			
		||||
        }
 | 
			
		||||
        // end of line not found, keep going
 | 
			
		||||
    }
 | 
			
		||||
    return Ok(!buf.is_empty());
 | 
			
		||||
    Ok(!buf.is_empty())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[test]
 | 
			
		||||
 
 | 
			
		||||
@@ -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())
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user