[][src]Function envmnt::evaluate_and_set_all

pub fn evaluate_and_set_all<F>(env: &IndexMap<String, String>, evaluate: F) where
    F: Fn(String) -> String

Sets all the provided env key/value pairs.

Arguments

  • env - The environment variables to set
  • evaluate - Evalute function which will modify the read value before it is loaded into the environment

Example

extern crate envmnt;
extern crate indexmap;

use indexmap::IndexMap;

fn main() {
    let mut env: IndexMap<String, String> = IndexMap::new();
    env.insert("MY_ENV_VAR".to_string(), "MY VALUE".to_string());
    env.insert("MY_ENV_VAR2".to_string(), "MY VALUE2".to_string());

    let eval_env = |value: String| {
        let mut buffer = String::from("VALUE-");
        buffer.push_str(&value);
        buffer
    };

    envmnt::evaluate_and_set_all(&env, eval_env);

    let mut value = envmnt::get_or_panic("MY_ENV_VAR");
    assert_eq!(value, "VALUE-MY VALUE");
    value = envmnt::get_or_panic("MY_ENV_VAR2");
    assert_eq!(value, "VALUE-MY VALUE2");
}