Function lock_env

Source
pub fn lock_env<'a>(
    variables: impl IntoIterator<Item = (&'a str, Option<impl AsRef<str>>)>,
) -> EnvGuard<'a>
Expand description

Lock the environment and set each given variable to its corresponding value. If the environment is already locked, this will block until the lock can be acquired. The returned guard will keep the environment locked so the calling test has exclusive access to it. Upon being dropped, the old environment values will be restored and then the environment will be unlocked.

§Note

There is a single mutex per process that locks the entire environment. This means multiple usages of by lock_env cannot run concurrently, even if they don’t modify any of the same environment variables. Keep your critical sections as short as possible to prevent slowdowns.