From db9afa0b06355028eafe3bc29fe0b2429ba8fd0a Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sun, 29 Mar 2026 00:52:16 +0800 Subject: Completed the first preliminary usable version of the Mingling framework. --- mingling_macros/src/chain.rs | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) (limited to 'mingling_macros/src/chain.rs') diff --git a/mingling_macros/src/chain.rs b/mingling_macros/src/chain.rs index 0c21c79..ddedc05 100644 --- a/mingling_macros/src/chain.rs +++ b/mingling_macros/src/chain.rs @@ -72,32 +72,6 @@ fn extract_return_type(sig: &Signature) -> syn::Result { } } -/// Implementation of the `#[chain]` attribute macro -/// -/// This macro transforms an async function into a struct that implements -/// the `Chain` trait. The struct name is specified in the attribute. -/// -/// # Examples -/// -/// ```ignore -/// use mingling_macros::chain; -/// -/// #[chain(InitEntry)] -/// pub async fn process(data: InitBegin) -> mingling::AnyOutput { -/// AnyOutput::new::("初始化成功!".to_string().into()) -/// } -/// ``` -/// -/// This generates: -/// ```ignore -/// pub struct InitEntry; -/// impl Chain for InitEntry { -/// type Previous = InitBegin; -/// async fn proc(data: Self::Previous) -> mingling::AnyOutput { -/// AnyOutput::new::("初始化成功!".to_string().into()) -/// } -/// } -/// ``` pub fn chain_attr(attr: TokenStream, item: TokenStream) -> TokenStream { // Parse the attribute arguments let chain_attr = parse_macro_input!(attr as ChainAttribute); @@ -160,5 +134,15 @@ pub fn chain_attr(attr: TokenStream, item: TokenStream) -> TokenStream { } }; + // Record the chain mapping + let chain_entry = quote! { + #struct_name => #previous_type, + }; + let mut chains = crate::CHAINS.lock().unwrap(); + let entry = chain_entry.to_string(); + if !chains.contains(&entry) { + chains.push(entry); + } + expanded.into() } -- cgit