Skip to main content

Environment

Trait Environment 

Source
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§

Source

fn set_var(&mut self, key: impl AsRef<OsStr>, value: impl AsRef<OsStr>)

Set an environment variable.

Source

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).
Source

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.

Source

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".

Implementors§