CommonLibrary/Environment/Environment.rs
1//! # Environment Trait
2//!
3//! Defines the core `Environment` marker trait, which serves as the foundation
4//! of the application's dependency injection and capability system.
5
6use std::sync::Arc;
7
8/// A marker trait for any struct that represents an application's environment.
9///
10/// An `Environment` is a container that holds all the concrete service
11/// implementations and application state necessary for executing
12/// `ActionEffect`s. By requiring that all environments implement this trait,
13
14/// the system can be generic over any valid environment context.
15///
16/// The `Send + Sync + 'static` bounds are critical, ensuring that the
17/// environment can be safely shared across asynchronous tasks and threads,
18
19/// which is essential for a concurrent application.
20pub trait Environment: Send + Sync + 'static {}
21
22/// A blanket implementation that allows a shared, reference-counted pointer to
23/// an `Environment` (`Arc<TEnvironment>`) to also be treated as an
24/// `Environment`.
25///
26/// This is a key ergonomic feature of the dependency injection system, enabling
27/// shared state to be passed around and used seamlessly without needing to
28/// constantly dereference `Arc` pointers.
29impl<TEnvironment:Environment + ?Sized> Environment for Arc<TEnvironment> {}