From b590a40891dcf843a2f3ca23d930aca4363e7ffe Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sun, 12 Oct 2025 18:15:36 +0800 Subject: feat: Add Clone implementation for ActionContext This enables ActionContext to be cloned when setting up process begin callbacks, resolving lifetime issues in callback registration. --- crates/system_action/src/action.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/system_action/src/action.rs b/crates/system_action/src/action.rs index 562a142..c8d7a18 100644 --- a/crates/system_action/src/action.rs +++ b/crates/system_action/src/action.rs @@ -1,6 +1,12 @@ +use serde::{Serialize, de::DeserializeOwned}; use tcp_connection::{error::TcpTargetError, instance::ConnectionInstance}; +use tokio::net::TcpStream; -pub trait Action { +pub trait Action +where + Args: Serialize + DeserializeOwned + Send, + Return: Serialize + DeserializeOwned + Send, +{ fn action_name() -> &'static str; fn is_remote_action() -> bool; @@ -13,7 +19,7 @@ pub trait Action { #[derive(Default)] pub struct ActionContext { - // Whether the action is executed locally or remotely + /// Whether the action is executed locally or remotely local: bool, /// The connection instance in the current context, @@ -35,6 +41,18 @@ impl ActionContext { ctx.local = false; ctx } + + /// Build connection instance from TcpStream + pub fn build_instance(mut self, stream: TcpStream) -> Self { + self.instance = Some(ConnectionInstance::from(stream)); + self + } + + /// Insert connection instance into context + pub fn insert_instance(mut self, instance: ConnectionInstance) -> Self { + self.instance = Some(instance); + self + } } impl ActionContext { -- cgit