Skip to main content

EnvSource

Trait EnvSource 

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

Read-only access to process environment variables.

Abstracts environment lookups so tests can inject deterministic values instead of mutating process-global state. Mutating the real environment races with other tests running in parallel threads of the same process.

Required Methods§

Source

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

Return the value of key.

Returns None when the variable is unset or its value is not valid UTF-8 — both cases are indistinguishable to callers, matching the std::env::var(..).ok() behaviour this trait replaces.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§