diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-10-12 18:15:36 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2025-10-12 18:15:36 +0800 |
| commit | b590a40891dcf843a2f3ca23d930aca4363e7ffe (patch) | |
| tree | 4c0cff57f7946c884e0762f4c256c8f206d6c4cb /crates/system_action | |
| parent | e12f167de8e16baa78c86b09eab75201281d3f95 (diff) | |
feat: Add Clone implementation for ActionContext
This enables ActionContext to be cloned when setting up process
begin callbacks, resolving lifetime issues in callback registration.
Diffstat (limited to 'crates/system_action')
| -rw-r--r-- | crates/system_action/src/action.rs | 22 |
1 files changed, 20 insertions, 2 deletions
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<Args, Return> { +pub trait Action<Args, Return> +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<Args, Return> { #[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 { |
