Function tmp_env::set_var [−][src]
pub fn set_var<K: AsRef<OsStr>, V: AsRef<OsStr>>(key: K, value: V) -> CurrentEnv
Expand description
Sets the environment variable k to the value v for the currently running process. It returns a datastructure to keep the environment variable set. When dropped the environment variable is removed
{ let _tmp_env = tmp_env::set_var("TEST_TMP_ENV", "myvalue"); assert_eq!(std::env::var("TEST_TMP_ENV"), Ok(String::from("myvalue"))); } assert!(std::env::var("TEST_TMP_ENV").is_err()); // Because guard is dropped then the environment variable is also automatically unset tmp_env::set_var("TEST_TMP_ENV_DROPPED", "myvaluedropped"); assert!(std::env::var("TEST_TMP_ENV_DROPPED").is_err());