From a6f73176a51c3aaef5c16b7c9d6f4923c9557d67 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 6 Oct 2025 17:20:19 +0800 Subject: feat: add default implementation and convenience methods to ActionContext - Implement Default trait for ActionContext - Add local() and remote() constructor methods - Make instance field optional for better flexibility --- crates/system_action/src/action.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'crates/system_action') diff --git a/crates/system_action/src/action.rs b/crates/system_action/src/action.rs index 14f1148..562a142 100644 --- a/crates/system_action/src/action.rs +++ b/crates/system_action/src/action.rs @@ -11,13 +11,30 @@ pub trait Action { ) -> impl std::future::Future> + Send; } +#[derive(Default)] pub struct ActionContext { // Whether the action is executed locally or remotely local: bool, /// The connection instance in the current context, /// used to interact with the machine on the other end - instance: ConnectionInstance, + instance: Option, +} + +impl ActionContext { + /// Generate local context + pub fn local() -> Self { + let mut ctx = ActionContext::default(); + ctx.local = true; + ctx + } + + /// Generate remote context + pub fn remote() -> Self { + let mut ctx = ActionContext::default(); + ctx.local = false; + ctx + } } impl ActionContext { @@ -32,7 +49,7 @@ impl ActionContext { } /// Get the connection instance in the current context - pub fn instance(&self) -> &ConnectionInstance { + pub fn instance(&self) -> &Option { &self.instance } } -- cgit