summaryrefslogtreecommitdiff
path: root/crates/system_action/action_macros
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-11-25 15:10:53 +0800
committer魏曹先生 <1992414357@qq.com>2025-11-25 15:10:53 +0800
commit292227c83753564cde90de7a4f43d9ef4660bd4c (patch)
tree5a8f4aaddf85b689985f129fc6d6d4c16e6a478e /crates/system_action/action_macros
parentf2ecc33f447ba0ccae261720019fa2820aa21875 (diff)
Improve documentation for system action and config file crates
Diffstat (limited to 'crates/system_action/action_macros')
-rw-r--r--crates/system_action/action_macros/src/lib.rs53
1 files changed, 48 insertions, 5 deletions
diff --git a/crates/system_action/action_macros/src/lib.rs b/crates/system_action/action_macros/src/lib.rs
index 4c03b63..e6616b4 100644
--- a/crates/system_action/action_macros/src/lib.rs
+++ b/crates/system_action/action_macros/src/lib.rs
@@ -2,13 +2,56 @@ use proc_macro::TokenStream;
use quote::quote;
use syn::{ItemFn, parse_macro_input};
-/// A procedural macro for generating structs that implement the Action trait
+/// # Macro - Generate Action
///
-/// Usage:
-/// #[action_gen] or #[action_gen(local)]
-/// pub fn my_action(ctx: ActionContext, arg: MyArg) -> Result<MyReturn, TcpTargetError> {
-/// todo!()
+/// When annotating a function with the `#[action_gen]` macro in the following format, it generates boilerplate code for client-server interaction
+///
+/// ```ignore
+/// #[action_gen]
+/// async fn action_name(ctx: ActionContext, argument: YourArgument) -> Result<YourResult, TcpTargetError> {
+/// // Write your client and server logic here
+/// if ctx.is_proc_on_remote() {
+/// // Server logic
+/// }
+/// if ctx.is_proc_on_local() {
+/// // Client logic
+/// }
+/// }
+/// ```
+///
+/// > WARNING:
+/// > For Argument and Result types, the `action_gen` macro only supports types that derive serde's Serialize and Deserialize
+///
+/// ## Generated Code
+///
+/// `action_gen` will generate the following:
+///
+/// 1. Complete implementation of Action<Args, Return>
+/// 2. Process / Register method
+///
+/// ## How to use
+///
+/// You can use your generated method as follows
+///
+/// ```ignore
+/// async fn main() -> Result<(), TcpTargetError> {
+///
+/// // Prepare your argument
+/// let args = YourArgument::default();
+///
+/// // Create a pool and context
+/// let mut pool = ActionPool::new();
+/// let ctx = ActionContext::local();
+///
+/// // Register your action
+/// register_your_action(&mut pool);
+///
+/// // Process your action
+/// proc_your_action(&pool, ctx, args).await?;
+///
+/// Ok(())
/// }
+/// ```
#[proc_macro_attribute]
pub fn action_gen(attr: TokenStream, item: TokenStream) -> TokenStream {
let input_fn = parse_macro_input!(item as ItemFn);