Skip to main content

EnvList

Struct EnvList 

Source
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

Source

pub fn new() -> Self

Build an empty environment.

§Returns

An EnvList with no variables.

§Errors and panics

This method does not fail or intentionally panic.

Source

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.

Source

pub fn from_pairs<I, K, V>(iter: I) -> Self
where I: IntoIterator<Item = (K, V)>, K: Into<String>, V: Into<String>,

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.

Source

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.

Trait Implementations§

Source§

impl Clone for EnvList

Source§

fn clone(&self) -> EnvList

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EnvList

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EnvList

Source§

fn default() -> EnvList

Returns the “default value” for a type. Read more
Source§

impl Env for EnvList

Source§

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

Return a variable’s value. Read more
Source§

fn has(&self, key: &str) -> bool

Return whether a variable is present with a non-empty value. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.