Mountain/Environment/ProviderTraitImplMacro.rs
1//! # ProviderTraitImplMacro (Environment)
2//!
3//! ## RESPONSIBILITIES
4//! Provides a declarative macro to generate `Requires<T>` trait implementations
5//! for MountainEnvironment, significantly reducing boilerplate code.
6//!
7//! ## ARCHITECTURAL ROLE
8//! This macro is part of the Environment module's Dependency Injection (DI)
9//! system, which enables components to request capabilities through traits.
10//! MountainEnvironment implements `Requires<T>` for all 25+ provider traits,
11//! and this macro automates the generation of those implementations.
12//!
13//! ## USAGE
14//!
15//! The macro is invoked at the module level to generate trait implementations:
16//!
17//! ```rust,ignore
18//! impl_provider!(CommandExecutor);
19//! impl_provider!(ConfigurationProvider);
20//! impl_provider!(FileSystemReader);
21//! ```
22//!
23//! This generates:
24//!
25//! ```rust,ignore
26//! impl Requires<dyn CommandExecutor> for MountainEnvironment {
27//! fn Require(&self) -> Arc<dyn CommandExecutor> {
28//! Arc::new(self.clone())
29//! }
30//! }
31//!
32//! impl Requires<dyn ConfigurationProvider> for MountainEnvironment {
33//! fn Require(&self) -> Arc<dyn ConfigurationProvider> {
34//! Arc::new(self.clone())
35//! }
36//! }
37//! ```
38//!
39//! ## KEY FEATURES
40//!
41//! - **Type Safety**: Generates type-safe implementations at compile time
42//! - **Zero Overhead**: Generated code is identical to hand-written
43//! implementations
44//! - **Maintainability**: Adding new providers requires only one macro
45//! invocation
46//! - **Consistency**: Ensures all implementations follow the same pattern
47//!
48//! ## PERFORMANCE CONSIDERATIONS
49//!
50//! The macro generates code with zero runtime overhead compared to hand-written
51//! implementations. The macro expansion happens at compile time, and the
52//! generated code is identical to what would be written manually.
53//!
54//! ## ERROR HANDLING
55//!
56//! The macro itself does not handle errors - any type checking or compilation
57//! errors will be reported by the Rust compiler on the generated code.
58
59/// Macro to generate `Requires<T>` trait implementations for
60/// MountainEnvironment.
61///
62/// This macro takes a trait name and generates an implementation of
63/// `Requires<dyn Trait>` for `MountainEnvironment`. The implementation returns
64/// `Arc::new(self.clone())`, which is the standard pattern for the DI
65/// container.
66///
67/// # Arguments
68///
69/// * `$trait_name` - The name of the trait (without `dyn` prefix)
70///
71/// # Example
72///
73/// ```rust,ignore
74/// impl_provider!(CommandExecutor);
75/// ```
76///
77/// Expands to:
78///
79/// ```rust,ignore
80/// impl Requires<dyn CommandExecutor> for MountainEnvironment {
81/// fn Require(&self) -> Arc<dyn CommandExecutor> {
82/// Arc::new(self.clone())
83/// }
84/// }
85/// ```
86///
87/// # Note
88///
89/// This macro is intended to be used within `MountainEnvironment.rs` after the
90/// `MountainEnvironment` struct definition. The macro assumes that
91/// `MountainEnvironment` implements all the traits that are being requested.
92#[macro_export]
93macro_rules! impl_provider {
94 ($trait_name:ident) => {
95 impl Requires<dyn $trait_name> for MountainEnvironment {
96 fn Require(&self) -> Arc<dyn $trait_name> { Arc::new(self.clone()) }
97 }
98 };
99}