diff --git a/ascii/src/lib.rs b/ascii/src/lib.rs index 09168298..9c51e3f2 100644 --- a/ascii/src/lib.rs +++ b/ascii/src/lib.rs @@ -205,24 +205,22 @@ impl<'a> Tokens<'a> { let mut whole_string = String::new(); let mut color = &DynColors::Ansi(AnsiColors::Default); - self.truncate(start, end).for_each(|token| { - match token { - Token::Char(chr) => { - width = width.saturating_sub(1); - colored_segment.push(chr); - } - Token::Color(col) => { - add_styled_segment(&mut whole_string, &colored_segment, *color, bold); - colored_segment = String::new(); - color = colors - .get(col as usize) - .unwrap_or(&DynColors::Ansi(AnsiColors::Default)); - } - Token::Space => { - width = width.saturating_sub(1); - colored_segment.push(' ') - } - }; + self.truncate(start, end).for_each(|token| match token { + Token::Char(chr) => { + width = width.saturating_sub(1); + colored_segment.push(chr); + } + Token::Color(col) => { + add_styled_segment(&mut whole_string, &colored_segment, *color, bold); + colored_segment = String::new(); + color = colors + .get(col as usize) + .unwrap_or(&DynColors::Ansi(AnsiColors::Default)); + } + Token::Space => { + width = width.saturating_sub(1); + colored_segment.push(' '); + } }); add_styled_segment(&mut whole_string, &colored_segment, *color, bold); @@ -267,15 +265,15 @@ fn token(s: &str, predicate: impl FnOnce(char) -> Option) -> ParseResult ParseResult { - let (s, _) = token(s, succeed_when(|c| c == '{'))?; + let (s, ()) = token(s, succeed_when(|c| c == '{'))?; let (s, color_index) = token(s, |c| c.to_digit(10))?; - let (s, _) = token(s, succeed_when(|c| c == '}'))?; + let (s, ()) = token(s, succeed_when(|c| c == '}'))?; Some((s, Token::Color(color_index))) } /// Parses a space. fn space_token(s: &str) -> ParseResult { - token(s, succeed_when(|c| c == ' ')).map(|(s, _)| (s, Token::Space)) + token(s, succeed_when(|c| c == ' ')).map(|(s, ())| (s, Token::Space)) } /// Parses any arbitrary character. This cannot fail. diff --git a/build.rs b/build.rs index 55b28da5..a52de4df 100644 --- a/build.rs +++ b/build.rs @@ -1,10 +1,10 @@ -use lazy_static::lazy_static; use regex::Regex; use std::collections::HashMap; use std::env; use std::error::Error; use std::fs::{self, File}; use std::path::Path; +use std::sync::LazyLock; use tera::{Context, Tera}; fn main() -> Result<(), Box> { @@ -37,12 +37,9 @@ fn strip_color_tokens_filter( value: &tera::Value, _args: &HashMap, ) -> tera::Result { - lazy_static! { - static ref COLOR_INDEX_REGEX: Regex = Regex::new(r"\{\d+\}").unwrap(); - } - let s = match value { - tera::Value::String(s) => s, - _ => return Err(tera::Error::msg("expected string")), + static COLOR_INDEX_REGEX: LazyLock = LazyLock::new(|| Regex::new(r"\{\d+\}").unwrap()); + let tera::Value::String(s) = value else { + return Err(tera::Error::msg("expected string")); }; Ok(tera::Value::String( COLOR_INDEX_REGEX.replace_all(s, "").to_string(), @@ -53,20 +50,17 @@ fn hex_to_rgb_filter( value: &tera::Value, _args: &HashMap, ) -> tera::Result { - let hex_string = match value { - tera::Value::String(s) => s, - _ => return Err(tera::Error::msg("expected string")), + let tera::Value::String(hex_string) = value else { + return Err(tera::Error::msg("expected string")); }; - let hex_string = match hex_string.strip_prefix('#') { - Some(s) => s, - None => return Err(tera::Error::msg("expected hex string starting with `#`")), + let Some(hex_string) = hex_string.strip_prefix('#') else { + return Err(tera::Error::msg("expected hex string starting with `#`")); }; if hex_string.len() != 6 { return Err(tera::Error::msg("expected a 6 digit hex string")); } - let channel_bytes = match u32::from_str_radix(hex_string, 16) { - Ok(n) => n, - Err(_) => return Err(tera::Error::msg("expected a valid hex string")), + let Ok(channel_bytes) = u32::from_str_radix(hex_string, 16) else { + return Err(tera::Error::msg("expected a valid hex string")); }; let r = (channel_bytes >> 16) & 0xFF; let g = (channel_bytes >> 8) & 0xFF; diff --git a/manifest/src/lib.rs b/manifest/src/lib.rs index 3c4c4ce4..2de2a603 100644 --- a/manifest/src/lib.rs +++ b/manifest/src/lib.rs @@ -45,7 +45,7 @@ fn parse_cargo_manifest(path: &Path) -> Result { let m = cargo_toml::Manifest::from_path(path) .with_context(|| format!("Failed to parse Cargo.toml at '{}'", path.display()))?; let package = m.package.context("Not a package (only a workspace)")?; - let description = package.description().map(|v| v.into()); + let description = package.description().map(Into::into); Ok(Manifest { manifest_type: ManifestType::Cargo, @@ -53,7 +53,7 @@ fn parse_cargo_manifest(path: &Path) -> Result { name: package.name.clone(), description, version: package.version().into(), - license: package.license().map(|x| x.into()), + license: package.license().map(Into::into), }) } diff --git a/src/cli.rs b/src/cli.rs index df2e481f..18551fe3 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -274,7 +274,7 @@ impl Default for InfoCliOptions { impl Default for TextForamttingCliOptions { fn default() -> Self { TextForamttingCliOptions { - text_colors: Default::default(), + text_colors: Vec::default(), iso_time: Default::default(), number_separator: NumberSeparator::Plain, no_bold: Default::default(), @@ -296,7 +296,7 @@ impl Default for ImageCliOptions { fn default() -> Self { ImageCliOptions { image: Option::default(), - image_protocol: Default::default(), + image_protocol: Option::default(), color_resolution: 16, } } @@ -353,7 +353,7 @@ pub enum NumberSeparator { } impl NumberSeparator { - fn separator(&self) -> &'static str { + fn separator(self) -> &'static str { match self { Self::Plain => "", Self::Comma => ",", diff --git a/src/info/authors.rs b/src/info/authors.rs index fa277f98..7764e467 100644 --- a/src/info/authors.rs +++ b/src/info/authors.rs @@ -162,7 +162,7 @@ impl InfoField for AuthorsInfo { fn title(&self) -> String { let mut title: String = "Author".into(); if self.authors.len() > 1 { - title.push('s') + title.push('s'); } title } diff --git a/src/info/churn.rs b/src/info/churn.rs index 48012c65..af5e2953 100644 --- a/src/info/churn.rs +++ b/src/info/churn.rs @@ -87,14 +87,14 @@ fn compute_file_churns( Ok(number_of_commits_by_file_path_sorted .into_iter() .filter_map(|(file_path, nbr_of_commits)| { - if !glob_set.is_match(file_path.to_string()) { + if glob_set.is_match(file_path.to_string()) { + None + } else { Some(FileChurn::new( file_path.to_string(), *nbr_of_commits, number_separator, )) - } else { - None } }) .take(number_of_file_churns_to_display) diff --git a/src/info/contributors.rs b/src/info/contributors.rs index 0ae8d389..6be201f7 100644 --- a/src/info/contributors.rs +++ b/src/info/contributors.rs @@ -32,7 +32,7 @@ impl InfoField for ContributorsInfo { if self.total_number_of_authors > self.number_of_authors_to_display { format_number(&self.total_number_of_authors, self.number_separator) } else { - "".to_string() + String::new() } } diff --git a/src/info/git/metrics.rs b/src/info/git/metrics.rs index a9da66ab..d68ff5ef 100644 --- a/src/info/git/metrics.rs +++ b/src/info/git/metrics.rs @@ -1,5 +1,4 @@ use super::sig::Sig; -use anyhow::Result; use gix::bstr::BString; use gix::date::Time; use std::collections::HashMap; @@ -21,7 +20,7 @@ impl GitMetrics { churn_pool_size: usize, time_of_first_commit: Option