pub fn get_set<K: AsRef<OsStr>, V: AsRef<OsStr>>(
    key: K,
    value: V
) -> Option<String>
Expand description

Sets the environment variable value and returns the previous value.

Arguments

  • key - The environment variable name
  • value - The environment variable value

Example

fn main() {
    envmnt::set("MY_ENV_VAR", "SOME VALUE");
    assert!(envmnt::is_equal("MY_ENV_VAR", "SOME VALUE"));

    let pre_value = envmnt::get_set("MY_ENV_VAR", "NEW VALUE");

    let value = envmnt::get_or("MY_ENV_VAR", "DEFAULT_VALUE");
    assert_eq!(value, "NEW VALUE");
    assert_eq!(pre_value.unwrap(), "SOME VALUE");
}