diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-10 16:30:20 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-10 16:30:20 +0800 |
| commit | 03b487f0f93ac32835149d4c1a0fb420341134f8 (patch) | |
| tree | 80e3e901c054581dcffc09da471053d15eb12560 /mingling_pathf/src/patterns/dispatcher.rs | |
| parent | 1be60c990f27cd9006fa3db8aa5bd623c33840e8 (diff) | |
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
Diffstat (limited to 'mingling_pathf/src/patterns/dispatcher.rs')
| -rw-r--r-- | mingling_pathf/src/patterns/dispatcher.rs | 24 |
1 files changed, 11 insertions, 13 deletions
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<AnalyzeItem> { 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<String>, Option<String>, Option<String>) { @@ -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::<String>() + c.as_str(), - } + c.next().map_or_else(String::new, |f| { + f.to_uppercase().collect::<String>() + 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() } |
