Skip to main content

Module env_source

Module env_source 

Source
Expand description

Process-env-or-injected-map abstraction for reads in production code.

Production code reads environment variables through Context::env_var, which routes through an injected EnvSource trait object. Production code uses ProcessEnvSource (calls std::env::var); tests inject a MapEnvSource via TestContextBuilder::env to drive deterministic branches without mutating the process env.

use anodizer_core::{EnvSource, MapEnvSource, ProcessEnvSource};

let prod = ProcessEnvSource;
let _ = prod.var("PATH");

let test_src = MapEnvSource::new()
    .with("GITHUB_TOKEN", "ghp_synthetic")
    .with("CI", "true");
assert_eq!(test_src.var("GITHUB_TOKEN"), Some("ghp_synthetic".to_string()));
assert_eq!(test_src.var("MISSING"), None);

Structs§

LayeredEnvSource
An EnvSource that overlays a small map of override entries on top of a base source.
MapEnvSource
Map-backed implementation for tests. Built from any IntoIterator<Item=(K,V)> (including HashMap<K, V> via the From impl below) or fluently via MapEnvSource::with.
ProcessEnvSource
Production implementation that reads std::env::var.

Traits§

EnvSource
Read-only lookup for an environment variable name.