diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-05-16 22:08:39 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-05-16 22:08:39 +0800 |
| commit | c48149a86eafcca967ef9aa947864fb4d0c727ea (patch) | |
| tree | c794eaef4435cb0f4ec8524861ebf3165f660097 /mingling_macros/src/program_setup.rs | |
| parent | 5fe400c006d9d143aa7b977cb13f95e7380754a5 (diff) | |
Replace hardcoded `ThisProgram` ident with shared constant
Diffstat (limited to 'mingling_macros/src/program_setup.rs')
| -rw-r--r-- | mingling_macros/src/program_setup.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/mingling_macros/src/program_setup.rs b/mingling_macros/src/program_setup.rs index 60a11a9..57b7e6c 100644 --- a/mingling_macros/src/program_setup.rs +++ b/mingling_macros/src/program_setup.rs @@ -3,6 +3,8 @@ use quote::quote; use syn::spanned::Spanned; use syn::{FnArg, Ident, ItemFn, Pat, PatType, ReturnType, Signature, Type, parse_macro_input}; +use crate::DEFAULT_PROGRAM_NAME; + /// Extracts the program parameter from function arguments fn extract_program_param(sig: &Signature) -> syn::Result<(Pat, Type)> { // The function should have exactly one parameter @@ -48,11 +50,13 @@ fn extract_return_type(sig: &Signature) -> syn::Result<()> { } pub fn setup_attr(attr: TokenStream, item: TokenStream) -> TokenStream { + let default_program_ident = crate::default_program_ident(); + // Parse the attribute arguments (e.g., MyProgram from #[program_setup(MyProgram)]) // If no argument is provided, use ThisProgram let (program_name, use_crate_prefix) = if attr.is_empty() { ( - Ident::new("ThisProgram", proc_macro2::Span::call_site()), + Ident::new(DEFAULT_PROGRAM_NAME, proc_macro2::Span::call_site()), true, ) } else { @@ -106,8 +110,8 @@ pub fn setup_attr(attr: TokenStream, item: TokenStream) -> TokenStream { #[doc(hidden)] #vis struct #struct_name; - impl ::mingling::setup::ProgramSetup<ThisProgram> for #struct_name { - fn setup(&mut self, program: &mut ::mingling::Program<ThisProgram>) { + impl ::mingling::setup::ProgramSetup<#default_program_ident> for #struct_name { + fn setup(&mut self, program: &mut ::mingling::Program<#default_program_ident>) { // Call the original function with the actual Program type #fn_name(program); } |
