pub struct LayeredEnvSource { /* private fields */ }Expand description
An EnvSource that overlays a small map of override entries on top of a
base source.
A lookup returns the override value when the name is present and non-empty; otherwise it delegates to the base source. This lets a caller inject one or two synthetic variables (e.g. a short-lived credential minted at runtime) so that env-driven code paths — scope-availability probes, token resolvers — observe the injected value without mutating the process environment or discarding the base source’s other variables.
An empty override string is treated as “not set” and falls through to the
base, matching how the rest of the codebase treats an empty credential
(is_some_and(|t| !t.is_empty())): overlaying ("X", "") cannot mask a
real base value.
use std::sync::Arc;
use anodizer_core::{EnvSource, LayeredEnvSource, MapEnvSource};
let base: Arc<dyn EnvSource> = Arc::new(MapEnvSource::new().with("A", "base-a"));
let layered = LayeredEnvSource::new(base, [("A", "override-a"), ("B", "override-b")]);
assert_eq!(layered.var("A"), Some("override-a".to_string())); // override wins
assert_eq!(layered.var("B"), Some("override-b".to_string())); // override-only key
assert_eq!(layered.var("MISSING"), None); // neither has itImplementations§
Source§impl LayeredEnvSource
impl LayeredEnvSource
Sourcepub fn new<I, K, V>(base: Arc<dyn EnvSource>, overrides: I) -> Self
pub fn new<I, K, V>(base: Arc<dyn EnvSource>, overrides: I) -> Self
Wrap base with the given (name, value) overrides. Empty override
values are retained but treated as absent by LayeredEnvSource::var
(they fall through to the base).
Trait Implementations§
Source§impl Clone for LayeredEnvSource
impl Clone for LayeredEnvSource
Source§fn clone(&self) -> LayeredEnvSource
fn clone(&self) -> LayeredEnvSource
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more