Function temp_env::with_vars_unset

source ·
pub fn with_vars_unset<K, F, R>(keys: impl AsRef<[K]>, closure: F) -> Rwhere
    K: AsRef<OsStr> + Clone + Eq + Hash,
    F: FnOnce() -> R,
Expand description

Unsets environment variables for the duration of the closure.

The previous values are restored when the closure completes or panics, before unwinding the panic.

This is a shorthand and identical to the following:

temp_env::with_vars(
    [
        ("FIRST_VAR", None::<&str>),
        ("SECOND_VAR", None::<&str>),
    ],
    || {
        // Run some code where `FIRST_VAR` and `SECOND_VAR` are unset (even if
        // they were set before)
    }
);