From 45cee7d8def7738d3347b201d3c54c0055817a4c Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 27 Oct 2025 17:20:01 +0800 Subject: fix: Make the ActionContext passed to on_proc_begin mutable --- crates/system_action/action_macros/src/lib.rs | 2 +- crates/system_action/src/action_pool.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'crates/system_action') diff --git a/crates/system_action/action_macros/src/lib.rs b/crates/system_action/action_macros/src/lib.rs index ce50073..7362cdf 100644 --- a/crates/system_action/action_macros/src/lib.rs +++ b/crates/system_action/action_macros/src/lib.rs @@ -64,7 +64,7 @@ fn generate_action_struct(input_fn: ItemFn, _is_local: bool) -> proc_macro2::Tok #fn_vis async fn #proc_this_action( pool: &action_system::action_pool::ActionPool, - ctx: action_system::action::ActionContext, + mut ctx: action_system::action::ActionContext, #arg_param_name: #arg_type ) -> Result<#return_type, tcp_connection::error::TcpTargetError> { let args_json = serde_json::to_string(&#arg_param_name) diff --git a/crates/system_action/src/action_pool.rs b/crates/system_action/src/action_pool.rs index c28de1e..c3ad4a1 100644 --- a/crates/system_action/src/action_pool.rs +++ b/crates/system_action/src/action_pool.rs @@ -7,7 +7,7 @@ use tcp_connection::error::TcpTargetError; use crate::action::{Action, ActionContext}; type ProcBeginCallback = for<'a> fn( - &'a ActionContext, + &'a mut ActionContext, args: &'a (dyn std::any::Any + Send + Sync), ) -> ProcBeginFuture<'a>; type ProcEndCallback = fn() -> ProcEndFuture; @@ -94,9 +94,9 @@ impl ActionPool { if let Some(action) = self.actions.get(action_name) { // Set action name and args in context for callbacks let context = context.set_action_name(action_name.to_string()); - let context = context.set_action_args(args_json.clone()); + let mut context = context.set_action_args(args_json.clone()); - self.exec_on_proc_begin(&context, &args_json).await?; + self.exec_on_proc_begin(&mut context, &args_json).await?; let result = action.process_json_erased(context, args_json).await?; self.exec_on_proc_end().await?; Ok(result) @@ -114,7 +114,7 @@ impl ActionPool { pub async fn process<'a, Args, Return>( &'a self, action_name: &'a str, - context: ActionContext, + mut context: ActionContext, args: Args, ) -> Result where @@ -122,7 +122,7 @@ impl ActionPool { Return: serde::Serialize + Send + 'static, { if let Some(action) = self.actions.get(action_name) { - self.exec_on_proc_begin(&context, &args).await?; + self.exec_on_proc_begin(&mut context, &args).await?; let result = action.process_erased(context, Box::new(args)).await?; let result = *result .downcast::() @@ -137,7 +137,7 @@ impl ActionPool { /// Executes the process begin callback if set async fn exec_on_proc_begin( &self, - context: &ActionContext, + context: &mut ActionContext, args: &(dyn std::any::Any + Send + Sync), ) -> Result<(), TcpTargetError> { if let Some(callback) = &self.on_proc_begin { -- cgit