[][src]Struct scoped_env::ScopedEnv

pub struct ScopedEnv<T> where
    T: AsRef<OsStr>, 
{ /* fields omitted */ }

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]

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]

impl<T> Drop for ScopedEnv<T> where
    T: AsRef<OsStr>, 
[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for ScopedEnv<T> where
    T: RefUnwindSafe
[src]

impl<T> Send for ScopedEnv<T> where
    T: Send
[src]

impl<T> Sync for ScopedEnv<T> where
    T: Sync
[src]

impl<T> Unpin for ScopedEnv<T> where
    T: Unpin
[src]

impl<T> UnwindSafe for ScopedEnv<T> where
    T: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.