pub unsafe fn remove_var<K: AsRef<OsStr>>(key: K)Expand description
Removes an environment variable from the environment of the currently running process.
§Safety
This function is sound to call in a single-threaded program.
This function is also always sound to call on Windows, in single-threaded and multi-threaded programs.
In multi-threaded programs on other operating systems, the only sound option is
to not use set_var or remove_var at all.
The exact requirement is: you
must ensure that there are no other threads concurrently writing or
reading(!) the environment through functions or global variables other
than the ones in this module. The problem is that these operating systems
do not provide a thread-safe way to read the environment, and most C
libraries, including libc itself, do not advertise which functions read
from the environment. Even functions from the Rust standard library may
read the environment without going through this module, e.g. for DNS
lookups from std::net::ToSocketAddrs. No stable guarantee is made about
which functions may read from the environment in future versions of a
library. All this makes it not practically possible for you to guarantee
that no other thread will read the environment, so the only sound option is
to not use set_var or remove_var in multi-threaded programs at all.
Discussion of this unsafety on Unix may be found in:
To prevent a child process from inheriting an environment variable, you can
instead use Command::env_remove or Command::env_clear.
§Panics
This function may panic if key is empty, contains an ASCII equals sign
'=' or the NUL character '\0', or when the value contains the NUL
character.