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_macros/src/systems/dispatch_tree_gen.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_macros/src/systems/dispatch_tree_gen.rs')
| -rw-r--r-- | mingling_macros/src/systems/dispatch_tree_gen.rs | 32 |
1 files changed, 3 insertions, 29 deletions
diff --git a/mingling_macros/src/systems/dispatch_tree_gen.rs b/mingling_macros/src/systems/dispatch_tree_gen.rs index d157feb..2b264f7 100644 --- a/mingling_macros/src/systems/dispatch_tree_gen.rs +++ b/mingling_macros/src/systems/dispatch_tree_gen.rs @@ -1,36 +1,10 @@ // Doc Not Optimize use std::collections::BTreeMap; -use just_fmt::snake_case; use proc_macro2::TokenStream; use quote::quote; -/// Generate the `get_nodes()` function body for a ProgramCollect impl. -pub(crate) fn gen_get_nodes(entries: &[(String, String, String)]) -> TokenStream { - let mut node_entries = Vec::new(); - - for (node_name, _disp_type, _entry_name) in entries { - let static_name_str = format!("__internal_dispatcher_{}", snake_case!(node_name)); - let static_ident = - proc_macro2::Ident::new(&static_name_str, proc_macro2::Span::call_site()); - let node_display_name = node_name.replace('.', " "); - let node_display_lit = syn::LitStr::new(&node_display_name, proc_macro2::Span::call_site()); - - node_entries.push(quote! { - (#node_display_lit.to_string(), &#static_ident) - }); - } - - quote! { - fn get_nodes() -> Vec<(String, &'static (dyn ::mingling::Dispatcher<Self::Enum> + Send + Sync))> { - vec![ - #(#node_entries),* - ] - } - } -} - -/// Generate the `dispatch_args()` function body for a ProgramCollect impl. +/// Generate the `dispatch_args()` function body for a `ProgramCollect` impl. /// /// Builds a hardcoded match tree: at each depth, group nodes by character. /// Single-node groups use `starts_with`; multi-node groups recurse with `nth()` match. @@ -63,7 +37,7 @@ pub(crate) fn gen_dispatch_args_trie(entries: &[(String, String, String)]) -> To /// Recursively build the trie match body. /// -/// `nodes`: slice of (display_name, disp_type) for commands that share the same prefix so far. +/// `nodes`: slice of (`display_name`, `disp_type`) for commands that share the same prefix so far. /// `depth`: The character index currently being matched. /// `no_match`: fallback code to run when no node in this subtree matches the input. /// @@ -95,7 +69,7 @@ fn build_dispatch_body( } let make_starts_with_arm = |name: &str, disp_type: &str| -> TokenStream { - let name_space = format!("{} ", name); + let name_space = format!("{name} "); let name_lit = syn::LitStr::new(&name_space, proc_macro2::Span::call_site()); let disp_ident = proc_macro2::Ident::new(disp_type, proc_macro2::Span::call_site()); let prefix_word_count = name.split_whitespace().count(); |
