Function envmnt::evaluate_and_set_all
source · [−]pub fn evaluate_and_set_all<F>(env: &IndexMap<String, String>, evaluate: F) where
F: Fn(String, String) -> Option<(String, String)>,
Expand description
Sets all the provided env key/value pairs.
Arguments
env
- The environment variables to setevaluate
- Evalute function which will modify the key/value before it is loaded into the environment
Example
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 = |key: String, value: String| {
let mut updated_key = String::from("KEY-");
updated_key.push_str(&key);
let mut updated_value = String::from("VALUE-");
updated_value.push_str(&value);
Some((updated_key, updated_value))
};
envmnt::evaluate_and_set_all(&env, eval_env);
let mut value = envmnt::get_or_panic("KEY-MY_ENV_VAR");
assert_eq!(value, "VALUE-MY VALUE");
value = envmnt::get_or_panic("KEY-MY_ENV_VAR2");
assert_eq!(value, "VALUE-MY VALUE2");
}