pub struct EnvGuard(/* private fields */);Expand description
RAII guard that proves ownership of the process-wide environment lock.
Obtain one with lock; while it is alive, no other thread can enter the
safe mutation methods on this type. Dropping the guard releases the lock.
Implementations§
Source§impl EnvGuard
impl EnvGuard
Sourcepub fn set_var(&self, key: impl AsRef<OsStr>, value: impl AsRef<OsStr>)
pub fn set_var(&self, key: impl AsRef<OsStr>, value: impl AsRef<OsStr>)
Set a process environment variable.
Safe because self proves the global env mutex is held, so no other
caller routed through this module is reading or writing the environment
concurrently.
Sourcepub fn remove_var(&self, key: impl AsRef<OsStr>)
pub fn remove_var(&self, key: impl AsRef<OsStr>)
Remove a process environment variable.
See Self::set_var for the safety argument.
Sourcepub fn restore_var<T: AsRef<OsStr>>(&self, key: &str, previous: Option<T>)
pub fn restore_var<T: AsRef<OsStr>>(&self, key: &str, previous: Option<T>)
Restore a variable to its previous value, or remove it if there was none.
Pairs with std::env::var_os snapshots taken before a mutation.
Auto Trait Implementations§
impl Freeze for EnvGuard
impl RefUnwindSafe for EnvGuard
impl !Send for EnvGuard
impl Sync for EnvGuard
impl Unpin for EnvGuard
impl UnsafeUnpin for EnvGuard
impl UnwindSafe for EnvGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more