summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-10-27 17:20:01 +0800
committer魏曹先生 <1992414357@qq.com>2025-10-27 17:20:01 +0800
commit45cee7d8def7738d3347b201d3c54c0055817a4c (patch)
treef88398a297c8eb4b8a5e582165bde1d29f6d2403
parent3d638844da6b540b1e70e25e6f7c49307b240078 (diff)
fix: Make the ActionContext passed to on_proc_begin mutable
-rw-r--r--crates/system_action/action_macros/src/lib.rs2
-rw-r--r--crates/system_action/src/action_pool.rs12
-rw-r--r--crates/vcs_actions/src/registry/client_registry.rs2
3 files changed, 8 insertions, 8 deletions
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<Return, TcpTargetError>
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::<Return>()
@@ -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 {
diff --git a/crates/vcs_actions/src/registry/client_registry.rs b/crates/vcs_actions/src/registry/client_registry.rs
index 484c4f4..a108910 100644
--- a/crates/vcs_actions/src/registry/client_registry.rs
+++ b/crates/vcs_actions/src/registry/client_registry.rs
@@ -26,7 +26,7 @@ pub fn client_action_pool() -> ActionPool {
}
async fn on_proc_begin(
- ctx: &ActionContext,
+ ctx: &mut ActionContext,
_args: &(dyn std::any::Any + Send + Sync),
) -> Result<(), TcpTargetError> {
// Is ctx remote