aboutsummaryrefslogtreecommitdiff
path: root/mingling_macros/src/chain.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-05-16 22:31:52 +0800
committer魏曹先生 <1992414357@qq.com>2026-05-16 22:31:52 +0800
commit60b91db3df168532f9143f0cafb7b5166e1dc78b (patch)
treeddb10f909a46033af16d725ab0dae8385227b985 /mingling_macros/src/chain.rs
parent05d07bbc627b59fd07a8764a972b4aac63a46f53 (diff)
Accept paths for program name parameters in macros
All proc macros (`pack!`, `dispatcher!`, `#[chain]`, `#[program_setup]`, `#[dispatcher_clap]`, `#[derive(Groupped)]`) now parse program names as `syn::Path` instead of bare `Ident`, allowing use of paths like `crate::MyProgram` or `my_crate::MyProgram`. The default program name `ThisProgram` is no longer re-exported or required as an import — generated code references `crate::ThisProgram` directly.
Diffstat (limited to 'mingling_macros/src/chain.rs')
-rw-r--r--mingling_macros/src/chain.rs12
1 files changed, 4 insertions, 8 deletions
diff --git a/mingling_macros/src/chain.rs b/mingling_macros/src/chain.rs
index 3c0cca5..fd1db65 100644
--- a/mingling_macros/src/chain.rs
+++ b/mingling_macros/src/chain.rs
@@ -5,8 +5,6 @@ use syn::{
FnArg, Ident, ItemFn, Pat, PatType, ReturnType, Signature, Type, TypePath, parse_macro_input,
};
-use crate::DEFAULT_PROGRAM_NAME;
-
/// Extracted information about a resource injection parameter
struct ResourceInjection {
var_name: Ident,
@@ -137,12 +135,10 @@ pub fn chain_attr(attr: TokenStream, item: TokenStream) -> TokenStream {
// Parse the attribute arguments (e.g., MyProgram from #[chain(MyProgram)])
// If no argument is provided, use ThisProgram
let (group_name, use_crate_prefix) = if attr.is_empty() {
- (
- Ident::new(DEFAULT_PROGRAM_NAME, proc_macro2::Span::call_site()),
- true,
- )
+ (crate::default_program_path(), true)
} else {
- (parse_macro_input!(attr as Ident), false)
+ let path: syn::Path = parse_macro_input!(attr as syn::Path);
+ (quote! { #path }, false)
};
// Parse the function item
@@ -235,7 +231,7 @@ pub fn chain_attr(attr: TokenStream, item: TokenStream) -> TokenStream {
let program_type = if use_crate_prefix {
crate::default_program_path()
} else {
- quote! { #group_name }
+ group_name.clone()
};
// Check for async fn + &mut combination, which is not supported