[−][src]Struct scoped_env::ScopedEnv
A rust lifetime scope for a set environment variable. When an instance goes out of scope it will automatically cleanup the environment
Implementations
impl<T> ScopedEnv<T> where
T: AsRef<OsStr>,
[src]
T: AsRef<OsStr>,
pub fn set(name: T, value: T) -> Self
[src]
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");
pub fn remove(name: T) -> Self
[src]
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
impl<T> AsRef<OsStr> for ScopedEnv<T> where
T: AsRef<OsStr>,
[src]
T: AsRef<OsStr>,
impl<T> Drop for ScopedEnv<T> where
T: AsRef<OsStr>,
[src]
T: AsRef<OsStr>,
Auto Trait Implementations
impl<T> RefUnwindSafe for ScopedEnv<T> where
T: RefUnwindSafe,
[src]
T: RefUnwindSafe,
impl<T> Send for ScopedEnv<T> where
T: Send,
[src]
T: Send,
impl<T> Sync for ScopedEnv<T> where
T: Sync,
[src]
T: Sync,
impl<T> Unpin for ScopedEnv<T> where
T: Unpin,
[src]
T: Unpin,
impl<T> UnwindSafe for ScopedEnv<T> where
T: UnwindSafe,
[src]
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,