diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-17 02:29:30 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-17 02:39:56 +0800 |
| commit | 6980fbf2f9fb4c599d8dc6ff549a8b3288eb24e9 (patch) | |
| tree | bc7049698955d7a40706ea691fd5bab526a6b5e5 /mingling_pathf/src/patterns/dispatcher.rs | |
| parent | 4c191b2b46a67a0dda6e9a867b40f45156af4f9c (diff) | |
refactor!: remove dynamic dispatcher registration API
Dispatchers are now always registered at compile time, removing the
`with_dispatcher` / `with_dispatchers` methods and the
`PathfinderConfig` API. The `dispatch_tree` feature now only controls
the matching strategy (trie vs linear list).
Diffstat (limited to 'mingling_pathf/src/patterns/dispatcher.rs')
| -rw-r--r-- | mingling_pathf/src/patterns/dispatcher.rs | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/mingling_pathf/src/patterns/dispatcher.rs b/mingling_pathf/src/patterns/dispatcher.rs index 56d2b97..5090052 100644 --- a/mingling_pathf/src/patterns/dispatcher.rs +++ b/mingling_pathf/src/patterns/dispatcher.rs @@ -3,7 +3,7 @@ //! extracts the generated type names from its arguments. It supports: //! - `Entry*` — the entry type (always generated) //! - `CMD*` — the dispatcher struct (always generated) -//! - `__internal_dispatcher_*` — the dispatch tree static (when `use_dispatch_tree` is `true`) +//! - `__internal_dispatcher_*` — the compile-time collected static (always generated) //! //! Supported forms: //! - Explicit: `dispatcher!("greet", CMDGreet => EntryGreet)` @@ -19,23 +19,15 @@ use crate::pattern_analyzer::{AnalyzeItem, AnalyzePattern}; /// Matches the `dispatcher!` macro, extracts: /// - `Entry*` — the entry type (always) /// - `CMD*` — the dispatcher struct (always) -/// - `__internal_dispatcher_*` — dispatch tree static (when `use_dispatch_tree` is true) -pub struct DispatcherPattern { - /// Whether the dispatcher generates a dispatch tree static (`__internal_dispatcher_*`). - pub use_dispatch_tree: bool, -} +/// - `__internal_dispatcher_*` — the compile-time collected static (always) +#[derive(Default)] +pub struct DispatcherPattern; impl DispatcherPattern { /// Creates a new `DispatcherPattern`. - /// - /// # Arguments - /// - /// * `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. #[must_use] - pub const fn new(use_dispatch_tree: bool) -> Self { - Self { use_dispatch_tree } + pub const fn new() -> Self { + Self } } @@ -62,7 +54,7 @@ impl AnalyzePattern for DispatcherPattern { if macro_name != "dispatcher" { continue; } - items.extend(extract_all_types(&m.mac.tokens, "", self.use_dispatch_tree)); + items.extend(extract_all_types(&m.mac.tokens, "")); } Item::Mod(item_mod) => { if let Some((_, nested)) = &item_mod.content { @@ -74,7 +66,6 @@ impl AnalyzePattern for DispatcherPattern { items.extend(extract_all_types( &m.mac.tokens, &item_mod.ident.to_string(), - self.use_dispatch_tree, )); } } @@ -98,11 +89,7 @@ fn macro_simple_name(m: &syn::ItemMacro) -> String { } /// Extracts all types generated by a `dispatcher!` call. -fn extract_all_types( - tokens: &proc_macro2::TokenStream, - module: &str, - use_dispatch_tree: bool, -) -> Vec<AnalyzeItem> { +fn extract_all_types(tokens: &proc_macro2::TokenStream, module: &str) -> Vec<AnalyzeItem> { let (cmd_name, cmd_struct, entry_struct) = parse_dispatcher_args(tokens); let Some(cmd_name) = cmd_name else { return Vec::new(); @@ -120,11 +107,9 @@ fn extract_all_types( items.push(AnalyzeItem::local(module.to_string(), cmd.clone())); } - // __internal_dispatcher_* — when configured - if use_dispatch_tree { - let internal_name = format!("__internal_dispatcher_{}", snake_case(&cmd_name)); - items.push(AnalyzeItem::local(module.to_string(), internal_name)); - } + // __internal_dispatcher_* — the compile-time collected static + let internal_name = format!("__internal_dispatcher_{}", snake_case(&cmd_name)); + items.push(AnalyzeItem::local(module.to_string(), internal_name)); items } |
