Skip to main content

EnvSource

Trait EnvSource 

Source
pub trait EnvSource: Send + Sync {
    // Required methods
    fn var(&self, name: &str) -> Option<String>;
    fn vars(&self) -> Vec<(String, String)>;
}
Expand description

Read-only lookup for an environment variable name.

Production code wires up ProcessEnvSource (which calls std::env::var). Tests wire up MapEnvSource to drive deterministic branches without mutating the process env.

Required Methods§

Source

fn var(&self, name: &str) -> Option<String>

Look up name and return its value, or None if unset.

Source

fn vars(&self) -> Vec<(String, String)>

Snapshot every (name, value) pair this source can enumerate.

Callers that need to scan the whole env (e.g. the determinism harness’s Windows inherit-everything pass, which drops a credential deny-list out of the host env) use this instead of std::env::vars() so a test can inject a closed map of fixture entries.

Required (no default): log/announce secret redaction builds its mask table from this snapshot, so a source that returned an empty Vec here would silently disable redaction while var(...) lookups kept working — a silent-failure footgun. Forcing every impl to provide vars() turns that mistake into a compile error. A source that genuinely cannot enumerate must return its full point-lookup domain (or, if truly unbounded, be reworked — never fall back to an empty snapshot).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§