pub struct ScopedEnv<T>{ /* private fields */ }
Expand description
A rust lifetime scope for a set environment variable. When an instance goes out of scope it will automatically cleanup the environment
Implementations§
Source§impl<T> ScopedEnv<T>
impl<T> ScopedEnv<T>
Sourcepub fn set(name: T, value: T) -> Self
pub fn set(name: T, value: T) -> Self
Sets the environment variable {name} to {value}. The
returned instance should be assigned to a _name
binding so that it lasts as long as the current
block.
use scoped_env::ScopedEnv;
let c = ScopedEnv::set("HELLO", "WORLD");
assert_eq!(std::env::var(c).unwrap().as_str(), "WORLD");
Sourcepub fn remove(name: T) -> Self
pub fn remove(name: T) -> Self
Removes the environment variable {name} from the
environment of the currently running process.
The returned instance should be assigned to a _name
binding. The variable value will be restored when the
handle goes out of scope.
use scoped_env::ScopedEnv;
std::env::set_var("HELLO", "WORLD");
{
let c = ScopedEnv::remove("HELLO");
assert!(std::env::var(c).is_err());
}
assert_eq!(std::env::var("HELLO").unwrap().as_str(), "WORLD");
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for ScopedEnv<T>where
T: Freeze,
impl<T> RefUnwindSafe for ScopedEnv<T>where
T: RefUnwindSafe,
impl<T> Send for ScopedEnv<T>where
T: Send,
impl<T> Sync for ScopedEnv<T>where
T: Sync,
impl<T> Unpin for ScopedEnv<T>where
T: Unpin,
impl<T> UnwindSafe for ScopedEnv<T>where
T: UnwindSafe,
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