Skip to main content

EnvSource

Trait EnvSource 

Source
pub trait EnvSource {
    // Required method
    fn var(&self, key: &str) -> Option<String>;

    // Provided method
    fn var_any(&self, keys: &[&str]) -> Option<String> { ... }
}
Expand description

A read-only view of environment variables.

Implemented by SystemEnv (the real process environment) in production and by an in-memory map in tests, so env-parsing boundaries can be tested without mutating the process-global environment.

Required Methods§

Source

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

Returns the value of key, or None if it is unset (or, for the process environment, not valid Unicode).

Provided Methods§

Source

fn var_any(&self, keys: &[&str]) -> Option<String>

Returns the first set value among keys, in order.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<T: EnvSource + ?Sized> EnvSource for &T

&T is an EnvSource whenever T is, so callers can pass &SystemEnv or &map_env to functions taking &impl EnvSource without ceremony.

Source§

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

Implementors§