aboutsummaryrefslogtreecommitdiff
path: root/mingling_macros/src/func/dispatcher.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-26 20:56:24 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-26 20:56:24 +0800
commit5714eba48ee9031d61858425583c219b881f2d13 (patch)
tree714a2f82d7652ab14433a9ea4c129c30f6d04597 /mingling_macros/src/func/dispatcher.rs
parent2cb8893711b73ccde946ca83e01dc315a9294c23 (diff)
feat(macros): split monolith into one-macro-per-file modules
Diffstat (limited to 'mingling_macros/src/func/dispatcher.rs')
-rw-r--r--mingling_macros/src/func/dispatcher.rs74
1 files changed, 3 insertions, 71 deletions
diff --git a/mingling_macros/src/func/dispatcher.rs b/mingling_macros/src/func/dispatcher.rs
index a61dd26..4e7c42f 100644
--- a/mingling_macros/src/func/dispatcher.rs
+++ b/mingling_macros/src/func/dispatcher.rs
@@ -1,13 +1,8 @@
-#[cfg(feature = "dispatch_tree")]
-use just_fmt::snake_case;
use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use syn::parse::{Parse, ParseStream};
-use syn::{Attribute, Ident, LitStr, Result as SynResult, Token};
-
-#[cfg(feature = "dispatch_tree")]
-use crate::COMPILE_TIME_DISPATCHERS;
+use syn::{Attribute, Ident, LitStr, Token};
enum DispatcherChainInput {
Default {
@@ -25,7 +20,7 @@ enum DispatcherChainInput {
}
impl Parse for DispatcherChainInput {
- fn parse(input: ParseStream) -> SynResult<Self> {
+ fn parse(input: ParseStream) -> syn::Result<Self> {
// Collect outer attributes for the CMD struct
let cmd_attrs = input.call(Attribute::parse_outer)?;
@@ -184,76 +179,13 @@ fn get_dispatch_tree_entry(
quote! {}
}
-#[cfg(feature = "dispatch_tree")]
-/// Input format: ("node.name", DispatcherType, EntryName)
-struct RegisterDispatcherInput {
- node_name: syn::LitStr,
- dispatcher_type: Ident,
- entry_name: Ident,
-}
-
-#[cfg(feature = "dispatch_tree")]
-impl Parse for RegisterDispatcherInput {
- fn parse(input: ParseStream) -> SynResult<Self> {
- let node_name = input.parse()?;
- input.parse::<Token![,]>()?;
- let dispatcher_type = input.parse()?;
- input.parse::<Token![,]>()?;
- let entry_name = input.parse()?;
- Ok(RegisterDispatcherInput {
- node_name,
- dispatcher_type,
- entry_name,
- })
- }
-}
-
-#[cfg(feature = "dispatch_tree")]
-pub(crate) fn register_dispatcher(input: TokenStream) -> TokenStream {
- let RegisterDispatcherInput {
- node_name,
- dispatcher_type,
- entry_name,
- } = syn::parse_macro_input!(input as RegisterDispatcherInput);
-
- let node_name_str = node_name.value();
- let static_name = format!(
- "__internal_dispatcher_{}",
- snake_case!(node_name_str.clone())
- );
- let static_ident = Ident::new(&static_name, proc_macro2::Span::call_site());
-
- // Register node info in the global collection at compile time
- // Format: "node.name:DispatcherType:EntryName"
- crate::get_global_set(&COMPILE_TIME_DISPATCHERS)
- .lock()
- .unwrap()
- .insert(format!(
- "{}:{}:{}",
- node_name_str, dispatcher_type, entry_name
- ));
-
- let expanded = quote! {
- #[doc(hidden)]
- #[allow(nonstandard_style)]
- pub static #static_ident: #dispatcher_type = #dispatcher_type;
- };
-
- expanded.into()
-}
-
-#[cfg(not(feature = "dispatch_tree"))]
-pub(crate) fn register_dispatcher(_input: TokenStream) -> TokenStream {
- quote! {}.into()
-}
-
/// Converts a dotted command name (e.g. "remote.add") to `PascalCase` (e.g. "`RemoteAdd`").
///
/// Each segment is split by `.`, the first character of each segment is uppercased,
/// and the segments are joined. This is used by the abbreviated `dispatcher!` syntax
/// (when `Command => Entry` is omitted) to auto-derive struct names.
#[cfg(feature = "extra_macros")]
-fn dotted_to_pascal_case(s: &str) -> String {
+pub(crate) fn dotted_to_pascal_case(s: &str) -> String {
s.split('.')
.map(|segment| {
let mut chars = segment.chars();