summaryrefslogtreecommitdiff
path: root/crates/system_action/action_macros/src
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-10-06 17:20:12 +0800
committer魏曹先生 <1992414357@qq.com>2025-10-06 17:20:12 +0800
commitd9a39247012130723b3c023ea9cdbe37d89f6f58 (patch)
tree626a622db424eacc72b5d01a14716b4f38816923 /crates/system_action/action_macros/src
parent2cf0239d3fd738d9e82909c94b41062c4765c375 (diff)
refactor: optimize procedural macros in action_system
- Add register_to_pool and process_at_pool helper methods to generated structs - Improve documentation with usage examples - Enhance macro-generated code structure
Diffstat (limited to 'crates/system_action/action_macros/src')
-rw-r--r--crates/system_action/action_macros/src/lib.rs34
1 files changed, 31 insertions, 3 deletions
diff --git a/crates/system_action/action_macros/src/lib.rs b/crates/system_action/action_macros/src/lib.rs
index 5d274ad..a7de9b6 100644
--- a/crates/system_action/action_macros/src/lib.rs
+++ b/crates/system_action/action_macros/src/lib.rs
@@ -55,10 +55,38 @@ fn generate_action_struct(input_fn: ItemFn, _is_local: bool) -> proc_macro2::Tok
}
}
+ impl #struct_name {
+ #fn_vis fn register_to_pool(pool: &mut action_system::action_pool::ActionPool) {
+ pool.register::<#struct_name, #arg_type, #return_type>();
+ }
+
+ #fn_vis async fn process_at_pool<'a>(
+ pool: &'a action_system::action_pool::ActionPool,
+ ctx: action_system::action::ActionContext,
+ #arg_param_name: #arg_type
+ ) -> Result<#return_type, tcp_connection::error::TcpTargetError> {
+ pool.process::<#arg_type, #return_type>(
+ Box::leak(string_proc::snake_case!(stringify!(#action_name_ident)).into_boxed_str()),
+ ctx,
+ #arg_param_name
+ ).await
+ }
+ }
+
+ #[allow(dead_code)]
#[deprecated = "This function is used by #[action_gen] as a template."]
- #[doc = " This function is used by #[action_gen] as a template to generate the struct. "]
- #[doc = " It is forbidden to call it anywhere."]
- #[doc = " and call it using the function name."]
+ #[doc = "Template function for #[[action_gen]] - do not call directly."]
+ #[doc = "Use the generated struct instead."]
+ #[doc = ""]
+ #[doc = "Register the action to the pool."]
+ #[doc = "```rust"]
+ #[doc = "YourActionPascalName::register_to_pool(&mut pool);"]
+ #[doc = "```"]
+ #[doc = ""]
+ #[doc = "Process the action at the pool."]
+ #[doc = "```rust"]
+ #[doc = "let result = YourActionPascalName::process_at_pool(&pool, ctx, arg).await?;"]
+ #[doc = "```"]
#fn_vis #fn_sig #fn_block
}
}