Mountain/RunTime/ApplicationRunTime/RuntimeStruct.rs
1//! # ApplicationRunTime (RunTime::ApplicationRunTime)
2//!
3//! ## RESPONSIBILITIES
4//!
5//! Defines the main ApplicationRunTime struct that provides effect execution
6//! and lifecycle management capabilities for the Mountain application.
7//!
8//! ## ARCHITECTURAL ROLE
9//!
10//! Core execution engine in Mountain's architecture that bridges declarative
11//! effect system with high-performance task execution through Echo scheduler.
12//!
13//! ## KEY COMPONENTS
14//!
15//! - **Scheduler**: Shared handle to Echo scheduler for task execution
16//! - **Environment**: Shared handle to MountainEnvironment for capability
17//! access
18//!
19//! ## ERROR HANDLING
20//!
21//! Uses Result types for fallible operations. The struct itself is infallible
22//! to create (all fields are Arc handles), but operations may return errors.
23//!
24//! ## LOGGING
25//!
26//! Uses log crate with appropriate severity levels for lifecycle events.
27//!
28//! ## PERFORMANCE CONSIDERATIONS
29//!
30//! - Uses Arc for shared state to minimize cloning
31//! - Struct derives Clone for cheap duplication
32//! - All fields are thread-safe Arc references
33//!
34//! ## TODO
35//!
36//! None
37
38use std::sync::Arc;
39
40use CommonLibrary::Environment::{Environment::Environment, HasEnvironment::HasEnvironment};
41use Echo::Scheduler::Scheduler::Scheduler;
42
43use crate::Environment::MountainEnvironment::MountainEnvironment;
44
45/// A `RunTime` that uses a high-performance, work-stealing scheduler (`Echo`)
46/// to execute all `ActionEffect`s.
47#[derive(Clone)]
48pub struct ApplicationRunTime {
49 /// A shared handle to the application's central scheduler.
50 pub Scheduler:Arc<Scheduler>,
51
52 /// A shared handle to the application's `Environment`, providing all
53 /// necessary capabilities.
54 pub Environment:Arc<MountainEnvironment>,
55}
56
57impl ApplicationRunTime {
58 /// Creates a new `ApplicationRunTime` that is powered by an `Echo`
59 /// scheduler.
60 pub fn Create(Scheduler:Arc<Scheduler>, Environment:Arc<MountainEnvironment>) -> Self {
61 log::info!("[ApplicationRunTime] New Echo-based instance created.");
62
63 Self { Scheduler, Environment }
64 }
65}
66
67// Implement the marker trait to satisfy the bounds on ApplicationRunTimeTrait
68impl HasEnvironment for ApplicationRunTime {
69 type EnvironmentType = MountainEnvironment;
70
71 fn GetEnvironment(&self) -> Arc<Self::EnvironmentType> { self.Environment.clone() }
72}
73
74// The ApplicationRunTime is not an environment itself, but it needs this marker
75// to satisfy some complex generic bounds in the effect system.
76impl Environment for ApplicationRunTime {}