pub struct EnvList { /* private fields */ }Expand description
A fixed list of environment variables.
Use this for an environment that does not come from this process, such as the variables an SSH client forwards or a set read from a configuration file, and for tests that need deterministic lookups.
Variables are stored as an ordered list of (key, value) pairs, matching
how an environment is passed around at the process boundary. Duplicate keys
are allowed, and lookups return the last matching value.
Implementations§
Source§impl EnvList
impl EnvList
Sourcepub fn from_process() -> Self
pub fn from_process() -> Self
Capture the current process environment.
The result is a snapshot: later changes to the process environment are
not visible to it. Use ProcessEnv to read through to the live
environment instead.
§Returns
An EnvList containing all variables yielded by std::env::vars at
the time of the call.
§Errors and panics
This method does not return errors. It has the same panic behavior as
std::env::vars if the process environment contains invalid data.
Sourcepub fn from_pairs<I, K, V>(iter: I) -> Self
pub fn from_pairs<I, K, V>(iter: I) -> Self
Build an environment from (key, value) pairs.
Pair order and duplicate keys are preserved. Later duplicates shadow
earlier values for get and has.
§Parameters
iter— variables to store.
§Returns
An EnvList containing the supplied variables.
§Errors and panics
This method does not return errors. It may panic only if allocation for the stored strings fails.
Sourcepub fn set(
&mut self,
key: impl Into<String>,
value: impl Into<String>,
) -> &mut Self
pub fn set( &mut self, key: impl Into<String>, value: impl Into<String>, ) -> &mut Self
Append a variable to the list.
If key is already present, the new value shadows earlier values for
get and has.
§Parameters
key— variable name.value— variable value.
§Returns
self, for chaining.
§Errors and panics
This method does not return errors. It may panic only if allocation for the stored strings fails.