pub trait Environment {
// Required methods
fn set_var(&mut self, key: impl AsRef<OsStr>, value: impl AsRef<OsStr>);
fn var(&self, key: impl AsRef<OsStr>) -> Result<String, VarError>;
fn var_os(&self, key: impl AsRef<OsStr>) -> Option<OsString>;
fn remove_var(&mut self, key: impl AsRef<OsStr>);
}Expand description
Represents a process’s environment.
Required Methods§
Sourcefn set_var(&mut self, key: impl AsRef<OsStr>, value: impl AsRef<OsStr>)
fn set_var(&mut self, key: impl AsRef<OsStr>, value: impl AsRef<OsStr>)
Set an environment variable.
Sourcefn var(&self, key: impl AsRef<OsStr>) -> Result<String, VarError>
fn var(&self, key: impl AsRef<OsStr>) -> Result<String, VarError>
Get an environment variable, checking for valid UTF-8. If valid UTF-8
checks are not needed, use var_os.
§Errors
- If a key doesn’t exist, it should return a
VarError::NotPresent. - If the environment variable value contains invalid UTF-8, it
should return
VarError::NotUnicode(OsString).
Sourcefn var_os(&self, key: impl AsRef<OsStr>) -> Option<OsString>
fn var_os(&self, key: impl AsRef<OsStr>) -> Option<OsString>
Get an environment variable. This does not check for valid UTF-8.
If a valid UTF-8 check is needed, use var instead.
Sourcefn remove_var(&mut self, key: impl AsRef<OsStr>)
fn remove_var(&mut self, key: impl AsRef<OsStr>)
Remove an environment variable from the current process environment.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.