From 03b487f0f93ac32835149d4c1a0fb420341134f8 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 10 Aug 2026 16:30:20 +0800 Subject: feat(pathf): enforce pedantic lints and update API ergonomics - Add `#[must_use]` to public constructors and getters - Change `init_with_config` to accept `&PathfinderConfig` instead of owned value - Refactor `map_or_else` and `or_insert_with` for clippy compliance - Add `#![deny(clippy::pedantic)]` and `#![deny(clippy::nursery)]` - Document error cases in public API docs - Simplify duplicated dispatcher_clap analysis logic --- mingling_pathf/src/patterns/dispatcher.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'mingling_pathf/src/patterns/dispatcher.rs') diff --git a/mingling_pathf/src/patterns/dispatcher.rs b/mingling_pathf/src/patterns/dispatcher.rs index cedad9f..85220b5 100644 --- a/mingling_pathf/src/patterns/dispatcher.rs +++ b/mingling_pathf/src/patterns/dispatcher.rs @@ -32,7 +32,8 @@ impl DispatcherPattern { /// * `use_dispatch_tree` — when `true`, the generated dispatcher also produces a /// `__internal_dispatcher_*` static dispatch tree item. Set this based on whether /// your macro invocation includes the `use_dispatch_tree` configuration. - pub fn new(use_dispatch_tree: bool) -> Self { + #[must_use] + pub const fn new(use_dispatch_tree: bool) -> Self { Self { use_dispatch_tree } } } @@ -102,9 +103,8 @@ fn extract_all_types( use_dispatch_tree: bool, ) -> Vec { let (cmd_name, cmd_struct, entry_struct) = parse_dispatcher_args(tokens); - let cmd_name = match cmd_name { - Some(n) => n, - None => return Vec::new(), + let Some(cmd_name) = cmd_name else { + return Vec::new(); }; let mut items = Vec::new(); @@ -128,7 +128,7 @@ fn extract_all_types( items } -/// Parses dispatcher arguments and returns (command_name, cmd_struct, entry_struct). +/// Parses dispatcher arguments and returns (`command_name`, `cmd_struct`, `entry_struct`). fn parse_dispatcher_args( tokens: &proc_macro2::TokenStream, ) -> (Option, Option, Option) { @@ -166,9 +166,8 @@ fn parse_dispatcher_args( } // Implicit form: "name" - let cmd_name = match extract_string_literal(&stream) { - Some(n) => n, - None => return (None, None, None), + let Some(cmd_name) = extract_string_literal(&stream) else { + return (None, None, None); }; let pascal = to_pascal_case(&cmd_name); ( @@ -192,15 +191,14 @@ fn to_pascal_case(s: &str) -> String { .filter(|s| !s.is_empty()) .map(|s| { let mut c = s.chars(); - match c.next() { - None => String::new(), - Some(f) => f.to_uppercase().collect::() + c.as_str(), - } + c.next().map_or_else(String::new, |f| { + f.to_uppercase().collect::() + c.as_str() + }) }) .collect() } -/// Simple snake_case conversion (replaces `.`, `-` with `_`). +/// Simple `snake_case` conversion (replaces `.`, `-` with `_`). fn snake_case(s: &str) -> String { s.replace(['.', '-'], "_").to_lowercase() } -- cgit