Function temp_env::with_var_unset

source ·
pub fn with_var_unset<K, F, R>(key: K, closure: F) -> Rwhere
    K: AsRef<OsStr> + Clone + Eq + Hash,
    F: FnOnce() -> R,
Expand description

Unsets a single environment variable for the duration of the closure.

The previous value is restored when the closure completes or panics, before unwinding the panic.

This is a shorthand and identical to the following:

temp_env::with_var("MY_ENV_VAR", None::<&str>, || {
    // Run some code where `MY_ENV_VAR` is unset.
});