diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-10-29 15:19:42 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2025-10-29 15:19:42 +0800 |
| commit | 305a95f5570d78164049474a82c54735f3d88957 (patch) | |
| tree | 2d029a7a74991f7fe29394ce411f58e832048f62 /crates | |
| parent | 3f0725503ee13eb83877165a530abbd5d2bda3c5 (diff) | |
update: Action.rs 1. Rename `insert` to `with_data` and `insert_arc` to
`with_arc_data` 2. Add new `insert_data` and `insert_arc_data` methods
that take &mut self
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/system_action/src/action.rs | 14 | ||||
| -rw-r--r-- | crates/vcs_actions/src/connection/action_service.rs | 2 |
2 files changed, 13 insertions, 3 deletions
diff --git a/crates/system_action/src/action.rs b/crates/system_action/src/action.rs index 9eef1db..ef1bf11 100644 --- a/crates/system_action/src/action.rs +++ b/crates/system_action/src/action.rs @@ -130,17 +130,27 @@ impl ActionContext { } /// Insert arbitrary data in the context - pub fn insert<T: Any + Send + Sync>(mut self, value: T) -> Self { + pub fn with_data<T: Any + Send + Sync>(mut self, value: T) -> Self { self.data.insert(TypeId::of::<T>(), Arc::new(value)); self } /// Insert arbitrary data as Arc in the context - pub fn insert_arc<T: Any + Send + Sync>(mut self, value: Arc<T>) -> Self { + pub fn with_arc_data<T: Any + Send + Sync>(mut self, value: Arc<T>) -> Self { self.data.insert(TypeId::of::<T>(), value); self } + /// Insert arbitrary data in the context + pub fn insert_data<T: Any + Send + Sync>(&mut self, value: T) { + self.data.insert(TypeId::of::<T>(), Arc::new(value)); + } + + /// Insert arbitrary data as Arc in the context + pub fn insert_arc_data<T: Any + Send + Sync>(&mut self, value: Arc<T>) { + self.data.insert(TypeId::of::<T>(), value); + } + /// Get arbitrary data from the context pub fn get<T: Any + Send + Sync>(&self) -> Option<&T> { self.data diff --git a/crates/vcs_actions/src/connection/action_service.rs b/crates/vcs_actions/src/connection/action_service.rs index ca236e7..3786fc5 100644 --- a/crates/vcs_actions/src/connection/action_service.rs +++ b/crates/vcs_actions/src/connection/action_service.rs @@ -184,7 +184,7 @@ async fn process_connection(stream: TcpStream, vault: Arc<Vault>, action_pool: A let ctx: ActionContext = ActionContext::remote().insert_instance(instance); // Insert vault into context - let ctx = ctx.insert_arc(vault); + let ctx = ctx.with_arc_data(vault); info!( "Process action `{}` with argument `{}`", |
