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
sourceimpl 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.
pub fn iter(&self) -> Iter<'_, OsString, OsString>
Trait Implementations
sourceimpl<'a> IntoIterator for &'a Env
impl<'a> IntoIterator for &'a Env
impl Eq for Env
impl StructuralEq for Env
impl StructuralPartialEq for Env
Auto Trait Implementations
impl RefUnwindSafe for Env
impl Send for Env
impl Sync for Env
impl Unpin for Env
impl UnwindSafe for Env
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more