From 02e07a18fcb3af9319c271f6e41d5b7785e2e436 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 10 Aug 2026 16:52:19 +0800 Subject: style: satisfy clippy pedantic and nursery lints --- arg_picker/src/parselib/arg_matcher.rs | 4 +-- arg_picker/src/parselib/flag_matcher.rs | 8 +++--- arg_picker/src/parselib/multi_arg_matcher.rs | 4 +-- arg_picker/src/parselib/pos_matcher.rs | 2 +- arg_picker/src/parselib/single_matcher.rs | 7 +++-- arg_picker/src/parselib/style.rs | 38 ++++++++++++++-------------- arg_picker/src/parselib/utils.rs | 30 ++++++++++------------ 7 files changed, 44 insertions(+), 49 deletions(-) (limited to 'arg_picker/src/parselib') diff --git a/arg_picker/src/parselib/arg_matcher.rs b/arg_picker/src/parselib/arg_matcher.rs index 38bb9cc..d26f6fb 100644 --- a/arg_picker/src/parselib/arg_matcher.rs +++ b/arg_picker/src/parselib/arg_matcher.rs @@ -29,7 +29,7 @@ pub struct ArgMatcher; impl ArgMatcher { /// Check whether `raw` matches `flag_str`, optionally with an inline value /// separated by the style's value separator (`=` for Unix, `:` for PowerShell). - #[inline(always)] + #[inline] fn matches(raw: &str, flag_str: &str, case_sensitive: bool, sep: char) -> bool { let eq_match = |r: &str, f: &str| r.len() > f.len() && r.as_bytes().get(f.len()) == Some(&(sep as u8)); @@ -46,7 +46,7 @@ impl ArgMatcher { /// Check whether the argument contains its value inline via the style's /// value separator (eq mode), so no extra mask slot is needed. - #[inline(always)] + #[inline] fn is_inline_value(raw: &str, flag_str: &str, sep: char) -> bool { raw.len() > flag_str.len() && raw.as_bytes().get(flag_str.len()) == Some(&(sep as u8)) } diff --git a/arg_picker/src/parselib/flag_matcher.rs b/arg_picker/src/parselib/flag_matcher.rs index e93d35a..2484cc9 100644 --- a/arg_picker/src/parselib/flag_matcher.rs +++ b/arg_picker/src/parselib/flag_matcher.rs @@ -18,7 +18,7 @@ impl Matcher for FlagMatcher { arg_info: &PickerArgInfo, ) -> Option { let possible_flags = build_possible_flags(style, arg_info); - let flag_refs: Vec<&str> = possible_flags.iter().map(|s| s.as_str()).collect(); + let flag_refs: Vec<&str> = possible_flags.iter().map(String::as_str).collect(); let end_of_options = seek_end_of_options(args, style); let result = get_seeked_first(multi_seek_eq(args, &flag_refs, style.case_sensitive)); @@ -45,7 +45,7 @@ fn single_pass_match_all( style: &ParserStyle, possible_flags: &[String], ) -> Vec { - let flag_refs: Vec<&str> = possible_flags.iter().map(|s| s.as_str()).collect(); + let flag_refs: Vec<&str> = possible_flags.iter().map(String::as_str).collect(); let eoo = style.end_of_options; let case_sensitive = style.case_sensitive; @@ -67,12 +67,12 @@ fn single_pass_match_all( // Only match flags before the end-of-options marker. if end_pos.is_none() { - let matched = if case_sensitive { + let is_matched = if case_sensitive { flag_refs.contains(&arg.raw) } else { flag_refs.iter().any(|s| arg.raw.eq_ignore_ascii_case(s)) }; - if matched { + if is_matched { matches.push(arg.raw_idx); } } diff --git a/arg_picker/src/parselib/multi_arg_matcher.rs b/arg_picker/src/parselib/multi_arg_matcher.rs index 748b1be..6791121 100644 --- a/arg_picker/src/parselib/multi_arg_matcher.rs +++ b/arg_picker/src/parselib/multi_arg_matcher.rs @@ -115,7 +115,7 @@ impl Matcher for MultiArgMatcher { } impl MultiArgMatcher { - #[inline(always)] + #[inline] fn flag_match(raw: &str, flag_str: &str, case_sensitive: bool, sep: char) -> bool { let eq = |r: &str, f: &str| r.len() > f.len() && r.as_bytes().get(f.len()) == Some(&(sep as u8)); @@ -130,7 +130,7 @@ impl MultiArgMatcher { } } - #[inline(always)] + #[inline] fn is_eq_match(raw: &str, flags: &[String], case_sensitive: bool, sep: char) -> bool { flags.iter().any(|f| { Self::flag_match(raw, f, case_sensitive, sep) diff --git a/arg_picker/src/parselib/pos_matcher.rs b/arg_picker/src/parselib/pos_matcher.rs index 279e01e..96aceb3 100644 --- a/arg_picker/src/parselib/pos_matcher.rs +++ b/arg_picker/src/parselib/pos_matcher.rs @@ -14,7 +14,7 @@ pub struct PositionalMatcher; impl PositionalMatcher { /// Check whether `raw` looks like a named flag (starts with a prefix). - #[inline(always)] + #[inline] fn is_flag_like(raw: &str, style: &ParserStyle) -> bool { raw.starts_with(style.long_prefix) || raw.starts_with(style.short_prefix) } diff --git a/arg_picker/src/parselib/single_matcher.rs b/arg_picker/src/parselib/single_matcher.rs index 25c4741..d7cf6a4 100644 --- a/arg_picker/src/parselib/single_matcher.rs +++ b/arg_picker/src/parselib/single_matcher.rs @@ -18,12 +18,11 @@ impl SingleMatcher { /// For named args, only complete pairs (flag + value) are kept. /// Flag occurrences without a following value or inline separator /// are dropped so they remain available for other matchers. - #[inline(always)] + #[inline] + #[must_use] pub fn tag(ctx: TagPhaseContext) -> Vec { if ctx.arg_info.positional { - PositionalMatcher::match_one(ctx.into()) - .map(|i| vec![i]) - .unwrap_or_default() + PositionalMatcher::match_one(ctx.into()).map_or_else(Vec::new, |i| vec![i]) } else { let args = ctx.args; let positions = ArgMatcher::match_all(ctx.into()); diff --git a/arg_picker/src/parselib/style.rs b/arg_picker/src/parselib/style.rs index 36ba8f0..81dfe72 100644 --- a/arg_picker/src/parselib/style.rs +++ b/arg_picker/src/parselib/style.rs @@ -56,7 +56,7 @@ impl<'a> ParserStyle<'a> { /// /// A `String` with the prefix and the flag name combined. #[must_use] - #[inline(always)] + #[inline] pub fn flag_string(&self, flag: F) -> String where F: Into>, @@ -88,7 +88,7 @@ pub enum FlagStr<'a> { Long(&'a str), } -impl<'a> From for FlagStr<'a> { +impl From for FlagStr<'_> { /// Converts a single character into a `FlagStr::Short`. fn from(c: char) -> Self { FlagStr::Short(c) @@ -129,36 +129,36 @@ impl<'a> From<&'a String> for FlagStr<'a> { #[repr(u8)] #[derive(Default, Clone, Copy, PartialEq, Eq)] pub enum ParserStyleNamingCase { - /// snake_case format: words are separated by underscores, all lowercase. + /// `snake_case` format: words are separated by underscores, all lowercase. /// /// Example: `brew_coffee` #[default] Snake, - /// camelCase format: first word is lowercase, subsequent words are capitalized. + /// `camelCase` format: first word is lowercase, subsequent words are capitalized. /// /// Example: `brewCoffee` Camel, - /// PascalCase format: every word starts with an uppercase letter. + /// `PascalCase` format: every word starts with an uppercase letter. /// /// Example: `BrewCoffee` Pascal, - /// kebab-case format: words are separated by hyphens, all lowercase. + /// `kebab-case` format: words are separated by hyphens, all lowercase. /// /// Example: `brew-coffee` Kebab, - /// dot.case format: words are separated by dots, all lowercase. + /// `dot.case` format: words are separated by dots, all lowercase. /// /// Example: `brew.coffee` Dot, - /// Title Case format: words are separated by spaces, each word capitalized. + /// `Title Case` format: words are separated by spaces, each word capitalized. /// /// Example: `Brew Coffee` Title, - /// lower case format: words are separated by spaces, all lowercase. + /// `lower case` format: words are separated by spaces, all lowercase. /// /// Example: `brew coffee` Lower, - /// UPPER CASE format: words are separated by spaces, all uppercase. + /// `UPPER CASE` format: words are separated by spaces, all uppercase. /// /// Example: `BREW COFFEE` Upper, @@ -187,14 +187,14 @@ impl ParserStyleNamingCase { S: Into + From, { match self { - ParserStyleNamingCase::Camel => just_fmt::camel_case!(s.into()).into(), - ParserStyleNamingCase::Pascal => just_fmt::pascal_case!(s.into()).into(), - ParserStyleNamingCase::Kebab => just_fmt::kebab_case!(s.into()).into(), - ParserStyleNamingCase::Snake => just_fmt::snake_case!(s.into()).into(), - ParserStyleNamingCase::Dot => just_fmt::dot_case!(s.into()).into(), - ParserStyleNamingCase::Title => just_fmt::title_case!(s.into()).into(), - ParserStyleNamingCase::Lower => just_fmt::lower_case!(s.into()).into(), - ParserStyleNamingCase::Upper => just_fmt::upper_case!(s.into()).into(), + Self::Camel => just_fmt::camel_case!(s.into()).into(), + Self::Pascal => just_fmt::pascal_case!(s.into()).into(), + Self::Kebab => just_fmt::kebab_case!(s.into()).into(), + Self::Snake => just_fmt::snake_case!(s.into()).into(), + Self::Dot => just_fmt::dot_case!(s.into()).into(), + Self::Title => just_fmt::title_case!(s.into()).into(), + Self::Lower => just_fmt::lower_case!(s.into()).into(), + Self::Upper => just_fmt::upper_case!(s.into()).into(), } } } @@ -238,7 +238,7 @@ pub const WINDOWS_STYLE: ParserStyle = ParserStyle { static GLOBAL_STYLE: OnceLock> = OnceLock::new(); static GLOBAL_STYLE_SET: AtomicBool = AtomicBool::new(false); -impl<'a> ParserStyle<'a> { +impl ParserStyle<'_> { /// Sets the global parser style. /// /// This function can only be called once. Subsequent calls will have no effect. diff --git a/arg_picker/src/parselib/utils.rs b/arg_picker/src/parselib/utils.rs index 47c5b55..dc4e091 100644 --- a/arg_picker/src/parselib/utils.rs +++ b/arg_picker/src/parselib/utils.rs @@ -8,7 +8,7 @@ use crate::{ /// This function generates formatted flag strings (e.g., `-h`, `--help`) from the short flag, /// long flag, and any aliases defined in the argument info. The long flag and alias names /// are converted according to the style's naming case convention before being formatted. -#[inline(always)] +#[must_use] pub fn build_possible_flags(style: &ParserStyle, arg_info: &PickerArgInfo) -> Vec { let mut possible_flags = vec![]; @@ -46,11 +46,7 @@ pub fn seek_single<'a>(raw_strs: &'a [&'a str]) -> Option<&'a str> { 1 => { let s = raw_strs[0]; let sep = ParserStyle::global_style().value_separator; - if let Some(pos) = s.rfind(sep) { - Some(&s[pos + 1..]) - } else { - Some(s) - } + s.rfind(sep).map_or(Some(s), |pos| Some(&s[pos + 1..])) } _ => Some(raw_strs[1]), } @@ -79,7 +75,7 @@ pub fn seek_end_of_options(args: &[MaskedArg], style: &ParserStyle) -> Option Vec { args.iter() .filter(|arg| { @@ -97,7 +93,7 @@ pub fn seek_eq(args: &[MaskedArg], string: &str, case_sensitive: bool) -> Vec Vec { args.iter() .filter(|arg| { @@ -115,7 +111,7 @@ pub fn seek_contains(args: &[MaskedArg], string: &str, case_sensitive: bool) -> /// /// Returns the indices of matching arguments. #[must_use] -#[inline(always)] +#[inline] pub fn seek_start_with(args: &[MaskedArg], string: &str, case_sensitive: bool) -> Vec { args.iter() .filter(|arg| { @@ -133,7 +129,7 @@ pub fn seek_start_with(args: &[MaskedArg], string: &str, case_sensitive: bool) - /// /// Returns the indices of matching arguments. #[must_use] -#[inline(always)] +#[inline] pub fn seek_end_with(args: &[MaskedArg], string: &str, case_sensitive: bool) -> Vec { args.iter() .filter(|arg| { @@ -151,7 +147,7 @@ pub fn seek_end_with(args: &[MaskedArg], string: &str, case_sensitive: bool) -> /// /// Returns the indices of matching arguments. #[must_use] -#[inline(always)] +#[inline] pub fn multi_seek_eq(args: &[MaskedArg], strings: &[&str], case_sensitive: bool) -> Vec { args.iter() .filter(|arg| { @@ -169,7 +165,7 @@ pub fn multi_seek_eq(args: &[MaskedArg], strings: &[&str], case_sensitive: bool) /// /// Returns the indices of matching arguments. #[must_use] -#[inline(always)] +#[inline] pub fn multi_seek_contains( args: &[MaskedArg], strings: &[&str], @@ -194,7 +190,7 @@ pub fn multi_seek_contains( /// /// Returns the indices of matching arguments. #[must_use] -#[inline(always)] +#[inline] pub fn multi_seek_start_with( args: &[MaskedArg], strings: &[&str], @@ -219,7 +215,7 @@ pub fn multi_seek_start_with( /// /// Returns the indices of matching arguments. #[must_use] -#[inline(always)] +#[inline] pub fn multi_seek_end_with( args: &[MaskedArg], strings: &[&str], @@ -245,10 +241,10 @@ pub fn multi_seek_end_with( /// This is useful for converting owned `String` vectors into borrowed `&str` slices /// for functions that take `&[&str]` or similar parameters. #[must_use] -#[inline(always)] +#[inline] #[doc(hidden)] pub fn vec_string_to_vec_str(input: &[String]) -> Vec<&str> { - input.iter().map(|s| s.as_str()).collect() + input.iter().map(String::as_str).collect() } /// Converts a `&Vec` into a `Vec<&str>` by borrowing each string's slice. @@ -270,7 +266,7 @@ macro_rules! vec_string_slice { /// /// Returns `Some(index)` if the vector is non-empty, otherwise `None`. #[must_use] -#[inline(always)] +#[inline] pub fn get_seeked_first(seeked: Vec) -> Option { seeked.into_iter().next() } -- cgit