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§
source§impl Env
impl Env
sourcepub fn from_current() -> Self
pub fn from_current() -> Self
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.
sourcepub fn insert(
&mut self,
key: impl Into<OsString>,
value: impl Into<OsString>
) -> &mut Self
pub fn insert(
&mut self,
key: impl Into<OsString>,
value: impl Into<OsString>
) -> &mut Self
Inserts a key-value pair into the environment, overriding the value if key was already
present.
sourcepub fn get(&self, key: impl AsRef<OsStr>) -> Option<OsString>
pub fn get(&self, key: impl AsRef<OsStr>) -> Option<OsString>
Returns a cloned value corresponding to the given key.
sourcepub fn contains_key(&self, key: impl AsRef<OsStr>) -> bool
pub fn contains_key(&self, key: impl AsRef<OsStr>) -> bool
Returns true if the environment contains a value for the specified key.