pub struct Env { /* private fields */ }
Expand description
Generic collection of environment variables.
§Examples
use libcnb::Env;
use std::process::Command;
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 the value corresponding to the given key.
Sourcepub fn get_string_lossy(&self, key: impl AsRef<OsStr>) -> Option<String>
pub fn get_string_lossy(&self, key: impl AsRef<OsStr>) -> Option<String>
Returns the value corresponding to the given key, interpreted as Unicode data.
Any non-Unicode sequences are replaced with
U+FFFD REPLACEMENT CHARACTER
.
See OsStr::to_string_lossy
for more details.
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.
pub fn iter(&self) -> Iter<'_, OsString, OsString>
Trait Implementations§
Source§impl<'a> IntoIterator for &'a Env
impl<'a> IntoIterator for &'a Env
impl Eq for Env
impl StructuralPartialEq for Env
Auto Trait Implementations§
impl Freeze for Env
impl RefUnwindSafe for Env
impl Send for Env
impl Sync for Env
impl Unpin for Env
impl UnwindSafe for Env
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.