Mountain/Environment/ProviderTraitImplMacro.rs
1//! # ProviderTraitImplMacro
2//!
3//! Declarative macro that generates `Requires<dyn T>` implementations for
4//! `MountainEnvironment`, eliminating the boilerplate of writing an identical
5//! `impl` block for each of the 25+ provider traits.
6//!
7//! Each invocation of `impl_provider!(TraitName)` expands to:
8//!
9//! ```rust,ignore
10//! impl Requires<dyn TraitName> for MountainEnvironment {
11//! fn Require(&self) -> Arc<dyn TraitName> {
12//! Arc::new(self.clone())
13//! }
14//! }
15//! ```
16//!
17//! This is correct because `MountainEnvironment` directly implements every
18//! provider trait, so cloning self and wrapping in `Arc` satisfies the
19//! `Requires<dyn T>` contract. The generated code is identical to a
20//! hand-written implementation - zero runtime overhead.
21//!
22//! Type safety and compilation errors for missing trait implementations are
23//! reported by the Rust compiler on the generated `impl` block, not on the
24//! macro call site.
25
26/// Macro to generate `Requires<dyn T>` trait implementations for
27/// `MountainEnvironment`.
28///
29/// # Arguments
30///
31/// * `$trait_name` - The name of the trait (without `dyn` prefix).
32///
33/// # Example
34///
35/// ```rust,ignore
36/// impl_provider!(CommandExecutor);
37/// ```
38///
39/// Expands to:
40///
41/// ```rust,ignore
42/// impl Requires<dyn CommandExecutor> for MountainEnvironment {
43/// fn Require(&self) -> Arc<dyn CommandExecutor> {
44/// Arc::new(self.clone())
45/// }
46/// }
47/// ```
48#[macro_export]
49macro_rules! impl_provider {
50 ($trait_name:ident) => {
51 impl Requires<dyn $trait_name> for MountainEnvironment {
52 fn Require(&self) -> Arc<dyn $trait_name> { Arc::new(self.clone()) }
53 }
54 };
55}