Skip to content

Commit ff8c0cb

Browse files
refactor(Common): Enhance effect system with Arc support and add TreeView DTO
This commit refines Land's core effect execution system and adds a missing DTO for TreeView configuration: 1. **Effect System Enhancements:** - Renamed `TCapability` to `TCapabilityProvider` in `ApplicationRunTime` and `ExecuteEffect` to clarify its role - Added `From<CommonError>` bound to effect errors for standardized error handling - Implemented blanket `ApplicationRunTime` for `Arc<TRunTime>` enabling shared runtime references - Added `HasEnvironment` implementation for `Arc<T>` simplifying environment access - Updated `Requires` trait documentation to reflect capability semantics 2. **TreeView DTO Addition:** - Added `TreeViewOptionsDTO` with serializable flags (`CanSelectMany`, `HasHandleDrag`, `HasHandleDrop`) - Organized DTO module structure by moving options to dedicated file These changes directly support Land's declarative effect architecture: - The runtime improvements enable `Mountain` to handle shared state more efficiently using Arc - Standardized error conversion ensures consistent error handling across all effect executions - The new DTO enables `Cocoon` to properly configure TreeViews through the `vine.proto` IPC layer - File organization aligns with Land's strict DTO management strategy BREAKING CHANGE: Effect methods now require `TError: From<CommonError>` and use raw trait objects in `Requires` bounds instead of Arc-wrapped types. Implementations must adjust capability dependencies accordingly.
1 parent 3deed54 commit ff8c0cb

File tree

7 files changed

+72
-32
lines changed

7 files changed

+72
-32
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ toml = { workspace = true }
66
async-trait = { workspace = true }
77
serde = { workspace = true }
88
serde_json = { workspace = true }
9-
thiserror.workspace = true
9+
thiserror = { workspace = true }
1010
url = { workspace = true }
1111

1212
[features]
Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,49 @@
11
//! # ApplicationRunTime Trait
22
//!
3-
//! Defines the `ApplicationRunTime` trait, which specifies the contract for any
4-
//! "engine" responsible for executing `ActionEffect`s.
3+
//! Defines the core `ApplicationRunTimeTrait`, which is the contract for any
4+
//! "engine" capable of executing `ActionEffect`s.
55
66
use std::sync::Arc;
77

88
use async_trait::async_trait;
99

1010
use super::ActionEffect::ActionEffect;
11-
use crate::Environment::{HasEnvironment::HasEnvironment, Requires::Requires};
11+
use crate::{
12+
Environment::{HasEnvironment::HasEnvironment, Requires::Requires},
13+
Error::CommonError::CommonError,
14+
};
1215

13-
/// A trait that defines the core contract for an application's runtime engine.
14-
///
15-
/// An `ApplicationRunTime` is the component that bridges the declarative world
16-
/// of `ActionEffect`s with the concrete world of execution. It is responsible
17-
/// for taking an effect, providing it with the necessary capabilities from its
18-
/// `Environment`, and running the resulting asynchronous operation to
19-
/// completion.
16+
/// The core trait for any runtime capable of executing `ActionEffect`s.
2017
#[async_trait]
2118
pub trait ApplicationRunTime: HasEnvironment + Send + Sync + 'static {
22-
/// Executes an `ActionEffect` that requires a specific capability from the
23-
/// environment.
19+
/// Executes an effect using the environment provided by the runtime.
2420
///
25-
/// This method is the heart of the effect execution system. It dynamically
26-
/// resolves the required capability (e.g., a trait object like
27-
/// `Arc<dyn FileSystemReader>`) from its managed environment and provides
28-
/// it to the effect's encapsulated function, which is then awaited.
29-
async fn Run<TCapability, TError, TOutput>(
21+
/// The runtime is responsible for acquiring the necessary capability from
22+
/// its environment and passing it to the effect's execution logic.
23+
async fn Run<TCapabilityProvider, TError, TOutput>(
3024
&self,
31-
Effect:ActionEffect<Arc<TCapability>, TError, TOutput>,
25+
Effect:ActionEffect<Arc<TCapabilityProvider>, TError, TOutput>,
3226
) -> Result<TOutput, TError>
3327
where
34-
TCapability: ?Sized + Send + Sync,
35-
Self::EnvironmentType: Requires<Arc<TCapability>>,
36-
TError: Send + Sync + 'static,
28+
TCapabilityProvider: ?Sized + Send + Sync + 'static,
29+
Self::EnvironmentType: Requires<TCapabilityProvider>,
30+
TError: From<CommonError> + Send + Sync + 'static,
3731
TOutput: Send + Sync + 'static;
3832
}
33+
34+
/// A blanket implementation that allows a shared `Arc` of a runtime to also be
35+
/// used as a runtime.
36+
#[async_trait]
37+
impl<TRunTime:ApplicationRunTime> ApplicationRunTime for Arc<TRunTime> {
38+
async fn Run<TCapabilityProvider, TError, TOutput>(
39+
&self,
40+
Effect:ActionEffect<Arc<TCapabilityProvider>, TError, TOutput>,
41+
) -> Result<TOutput, TError>
42+
where
43+
TCapabilityProvider: ?Sized + Send + Sync + 'static,
44+
Self::EnvironmentType: Requires<TCapabilityProvider>,
45+
TError: From<CommonError> + Send + Sync + 'static,
46+
TOutput: Send + Sync + 'static, {
47+
(**self).Run(Effect).await
48+
}
49+
}

Source/Effect/ExecuteEffect.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use std::sync::Arc;
77

88
use super::{ActionEffect::ActionEffect, ApplicationRunTime::ApplicationRunTime};
9-
use crate::Environment::Requires::Requires;
9+
use crate::{Environment::Requires::Requires, Error::CommonError::CommonError};
1010

1111
/// A generic effect execution helper that takes a runtime and an effect, and
1212
/// executes the effect using that runtime.
@@ -24,15 +24,15 @@ use crate::Environment::Requires::Requires;
2424
/// ExecuteEffect(RunTime, ReadEffect).await
2525
/// }
2626
/// ```
27-
pub async fn ExecuteEffect<TRunTime, TCapability, TError, TOutput>(
27+
pub async fn ExecuteEffect<TRunTime, TCapabilityProvider, TError, TOutput>(
2828
RunTime:Arc<TRunTime>,
29-
Effect:ActionEffect<Arc<TCapability>, TError, TOutput>,
29+
Effect:ActionEffect<Arc<TCapabilityProvider>, TError, TOutput>,
3030
) -> Result<TOutput, TError>
3131
where
3232
TRunTime: ApplicationRunTime,
33-
TCapability: ?Sized + Send + Sync,
34-
TRunTime::EnvironmentType: Requires<Arc<TCapability>>,
35-
TError: Send + Sync + 'static,
33+
TCapabilityProvider: ?Sized + Send + Sync + 'static,
34+
TRunTime::EnvironmentType: Requires<TCapabilityProvider>,
35+
TError: From<CommonError> + Send + Sync + 'static,
3636
TOutput: Send + Sync + 'static, {
3737
// The RunTime::Run method expects an effect whose closure takes the capability.
3838
// This now matches perfectly.

Source/Environment/HasEnvironment.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,13 @@ pub trait HasEnvironment {
2020
/// Gets a shared, reference-counted pointer to the environment.
2121
fn GetEnvironment(&self) -> Arc<Self::EnvironmentType>;
2222
}
23+
24+
/// A blanket implementation for `Arc<T>`. This allows code to treat
25+
/// an `Arc<TRunTime>` as if it were `TRunTime` for the purpose of getting the
26+
/// environment. This is required by the blanket `impl ApplicationRunTime for
27+
/// Arc<TRunTime>` which has a `where Self: HasEnvironment` bound.
28+
impl<T:HasEnvironment> HasEnvironment for Arc<T> {
29+
type EnvironmentType = T::EnvironmentType;
30+
31+
fn GetEnvironment(&self) -> Arc<Self::EnvironmentType> { (**self).GetEnvironment() }
32+
}

Source/Environment/Requires.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use super::Environment::Environment;
1717
/// to perform its operation.
1818
///
1919
/// The `Capability` is typically a trait object, such as
20-
/// `Arc<dyn FileSystemReader>`.
20+
/// `dyn FileSystemReader`.
2121
pub trait Requires<Capability:?Sized>: Environment {
2222
/// Returns the required capability from the environment, wrapped in an
2323
/// `Arc` for safe, shared ownership.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! # TreeViewOptionsDTO
2+
//!
3+
//! Defines the Data Transfer Object for a tree view's configuration options.
4+
5+
#![allow(non_snake_case, non_camel_case_types)]
6+
7+
use serde::{Deserialize, Serialize};
8+
9+
/// A struct that holds the configuration options for a tree view instance
10+
/// registered by an extension.
11+
#[derive(Serialize, Deserialize, Debug, Clone)]
12+
#[serde(rename_all = "PascalCase")]
13+
pub struct TreeViewOptionsDTO {
14+
#[serde(default)]
15+
pub CanSelectMany:bool,
16+
#[serde(default)]
17+
pub HasHandleDrag:bool,
18+
#[serde(default)]
19+
pub HasHandleDrop:bool,
20+
}

Source/TreeView/DTO/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
#![allow(non_snake_case, non_camel_case_types)]
77

88
pub mod TreeItemDTO;
9+
pub mod TreeViewOptionsDTO;
10+
911
// mod RevealOptionsDTO; // Placeholder for future DTOs
1012
// mod TreeViewBadgeDTO;
11-
// mod TreeViewOptionsDTO;
12-
13-
// pub use self::TreeItemDTO::TreeItemDTO;

0 commit comments

Comments
 (0)