Struct libcnb::Env

source · []
pub struct Env { /* private fields */ }
Expand description

Generic collection of environment variables.

Examples

use std::process::Command;
use libcnb::Env;

let mut env = Env::new();
env.insert("FOO", "BAR");
env.insert("BAZ", "BLAH");

let output = Command::new("printenv")
    .env_clear()
    .envs(&env)
    .output()
    .unwrap();

assert_eq!(
    "BAZ=BLAH\nFOO=BAR\n",
    String::from_utf8_lossy(&output.stdout)
);

Implementations

Creates a new Env from all the environment variables of the current process.

The returned Env contains a snapshot of the process’s environment variables at the time of this invocation. Modifications to environment variables afterwards will not be reflected in the returned value.

See std::env::vars_os

Creates an empty Env struct.

Inserts a key-value pair into the environment, overriding the value if key was already present.

Returns a cloned value corresponding to the given key.

Returns true if the environment contains a value for the specified key.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Performs the conversion.

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.