aboutsummaryrefslogtreecommitdiff
path: root/mingling_macros/src/attr
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-17 02:29:30 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-17 02:39:56 +0800
commit6980fbf2f9fb4c599d8dc6ff549a8b3288eb24e9 (patch)
treebc7049698955d7a40706ea691fd5bab526a6b5e5 /mingling_macros/src/attr
parent4c191b2b46a67a0dda6e9a867b40f45156af4f9c (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/attr')
-rw-r--r--mingling_macros/src/attr/command.rs9
-rw-r--r--mingling_macros/src/attr/dispatcher_clap.rs24
2 files changed, 12 insertions, 21 deletions
diff --git a/mingling_macros/src/attr/command.rs b/mingling_macros/src/attr/command.rs
index c2ddde3..4542bd7 100644
--- a/mingling_macros/src/attr/command.rs
+++ b/mingling_macros/src/attr/command.rs
@@ -321,19 +321,16 @@ pub(crate) fn command_attr(attr: TokenStream, item: TokenStream) -> TokenStream
fn_name.span(),
);
- // dispatcher internal static (only exists with dispatch_tree feature)
- #[cfg(feature = "dispatch_tree")]
+ // dispatcher internal static (always exists now that dispatchers are
+ // collected at compile time regardless of the `dispatch_tree` feature)
let snaked_node = just_fmt::snake_case!(names.node_lit.value());
- #[cfg(feature = "dispatch_tree")]
let dispatcher_internal = {
let ident = Ident::new(
- &format!("__internal_dispatcher_{}", snaked_node),
+ &format!("__internal_dispatcher_{snaked_node}"),
fn_name.span(),
);
quote! { #vis use super::#ident; }
};
- #[cfg(not(feature = "dispatch_tree"))]
- let dispatcher_internal = quote! {};
let cmd_name = &names.cmd_name;
let entry_type = &names.entry_type;
diff --git a/mingling_macros/src/attr/dispatcher_clap.rs b/mingling_macros/src/attr/dispatcher_clap.rs
index 9aa7779..2f45b14 100644
--- a/mingling_macros/src/attr/dispatcher_clap.rs
+++ b/mingling_macros/src/attr/dispatcher_clap.rs
@@ -174,8 +174,8 @@ pub(crate) fn dispatcher_clap_attr(attr: TokenStream, item: TokenStream) -> Toke
None
};
- let dispatch_tree_entry =
- get_dispatch_tree_entry(&command_name_str, dispatcher_struct, struct_name);
+ let compile_time_registration =
+ get_compile_time_registration(&command_name_str, dispatcher_struct, struct_name);
let expanded = quote! {
// Keep the original struct definition
@@ -187,8 +187,8 @@ pub(crate) fn dispatcher_clap_attr(attr: TokenStream, item: TokenStream) -> Toke
// Generate the help block if enabled
#help_gen
- // Dispatch tree registration (if feature enabled)
- #dispatch_tree_entry
+ // Compile-time registration
+ #compile_time_registration
// Generate the dispatcher struct
#[doc(hidden)]
@@ -223,8 +223,11 @@ pub(crate) fn dispatcher_clap_attr(attr: TokenStream, item: TokenStream) -> Toke
expanded.into()
}
-#[cfg(feature = "dispatch_tree")]
-fn get_dispatch_tree_entry(
+/// Registers the dispatcher at compile time (collects its node into the
+/// global `COMPILE_TIME_DISPATCHERS` registry and emits the
+/// `__internal_dispatcher_*` static), regardless of the `dispatch_tree`
+/// feature.
+fn get_compile_time_registration(
command_name_str: &str,
dispatcher_struct: &Ident,
entry_name: &Ident,
@@ -234,12 +237,3 @@ fn get_dispatch_tree_entry(
::mingling::macros::register_dispatcher!(#node_name_lit, #dispatcher_struct, #entry_name);
}
}
-
-#[cfg(not(feature = "dispatch_tree"))]
-fn get_dispatch_tree_entry(
- _command_name_str: &str,
- _dispatcher_struct: &Ident,
- _entry_name: &Ident,
-) -> proc_macro2::TokenStream {
- quote! {}
-}