Module io_providers::env [] [src]

Providers of environment data, such as the working directory and environment variables.

Examples

extern crate io_providers;

use std::path::{Path, PathBuf};
use io_providers::env;
use io_providers::env::Provider;

fn path_is_foobar<E: env::Provider>(env: &mut E) -> bool {
    let cur_dir = env.current_dir().unwrap();
    cur_dir == PathBuf::from("/foo/bar")
}

fn main() {
    test_path_is_foobar();

    // Use a local environment provider here to interact with the system environment
    path_is_foobar(&mut env::Local::new());
}

fn test_path_is_foobar() {
    // Use a virtual environment provider here to test the functionality of `path_is_foobar()`
    let mut env = env::Virtual::new();
    env.set_current_dir(Path::new("/nope"));

    assert!(!path_is_foobar(&mut env));

    env.set_current_dir(Path::new("/foo/bar"));

    assert!(path_is_foobar(&mut env));
}

Structs

Local

Provides access to the local environment (e.g. what the corresponding std::env functions would access).

Virtual

Provides access to a virtual environment, which can be configured independently from the local system.

Traits

Provider

Provides access to environment data, such as working directory and environment variables.