diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-04-10 23:38:47 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-04-10 23:38:47 +0800 |
| commit | 839326946560166da84c04d4770385795d96cff0 (patch) | |
| tree | edac8bcb0ca29e3c83eec1d9468e5b899a7f7729 /mingling_macros/src/chain.rs | |
| parent | b18749170b6006e53976dbb6df9f59a3b9c34127 (diff) | |
Add completion system with shell context and dispatcher integration
Diffstat (limited to 'mingling_macros/src/chain.rs')
| -rw-r--r-- | mingling_macros/src/chain.rs | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/mingling_macros/src/chain.rs b/mingling_macros/src/chain.rs index 924931e..fbf6a6b 100644 --- a/mingling_macros/src/chain.rs +++ b/mingling_macros/src/chain.rs @@ -176,13 +176,8 @@ pub fn chain_attr(attr: TokenStream, item: TokenStream) -> TokenStream { }; // Record the chain mapping - let chain_entry = quote! { - #struct_name => #previous_type, - }; - - let chain_exist_entry = quote! { - Self::#previous_type => true, - }; + let chain_entry = build_chain_arm(&struct_name, &previous_type); + let chain_exist_entry = build_chain_exist_arm(&previous_type); let mut chains = crate::CHAINS.lock().unwrap(); let mut chain_exist = crate::CHAINS_EXIST.lock().unwrap(); @@ -192,17 +187,23 @@ pub fn chain_attr(attr: TokenStream, item: TokenStream) -> TokenStream { let chain_exist_entry = chain_exist_entry.to_string(); let previous_type_str = previous_type.to_token_stream().to_string(); - if !chains.contains(&chain_entry) { - chains.push(chain_entry); - } + chains.insert(chain_entry); + chain_exist.insert(chain_exist_entry); + packed_types.insert(previous_type_str); - if !chain_exist.contains(&chain_exist_entry) { - chain_exist.push(chain_exist_entry); - } + expanded.into() +} - if !packed_types.contains(&previous_type_str) { - packed_types.push(previous_type_str); +/// Builds a match arm for chain mapping +pub fn build_chain_arm(struct_name: &Ident, previous_type: &TypePath) -> proc_macro2::TokenStream { + quote! { + #struct_name => #previous_type, } +} - expanded.into() +/// Builds a match arm for chain existence check +pub fn build_chain_exist_arm(previous_type: &TypePath) -> proc_macro2::TokenStream { + quote! { + Self::#previous_type => true, + } } |
