Function build_allowed_env_list

Source
pub fn build_allowed_env_list<'a>(
    env_list: Option<Vec<String>>,
    defaults: &[&'a str],
) -> Vec<Option<&'a str>>
Expand description

Build a list of allowed values from the given defaults using the env_list.

The entries in defaults are preserved, in order, and are replaced with None in the returned list if they are disabled.

// Passing no `env_list` returns the defaults:
assert_eq!(build_allowed_env_list(None, &["a"]), vec![Some("a")]);
// We can build up a subset of the defaults:
assert_eq!(build_allowed_env_list(Some(vec!["b".to_string()]), &["a","b"]), vec![None, Some("b")]);
// Alternately we can subtract from the defaults:
assert_eq!(build_allowed_env_list(Some(vec!["-a".to_string()]), &["a","b"]), vec![None, Some("b")]);
// We are not allowed to mix set "addition" and "subtraction"; the following
// will panic:
build_allowed_env_list(Some(vec!["-a".to_string(), "b".to_string()]), &["a", "b"]);
// This will also panic if invalid values are used:
build_allowed_env_list(Some(vec!["c".to_string()]), &["a", "b"]);