pub fn set_optional<K: AsRef<OsStr>, V: AsRef<OsStr>>(
    key: K,
    value: &Option<V>
) -> bool
Expand description

Sets the environment variable if the provided option contains a value.

Arguments

  • key - The environment variable name
  • value - The optional value to set

Example

fn main() {
    let output = envmnt::set_optional("MY_ENV_VAR", &Some("OPTIONAL VALUE"));

    assert!(output);
    assert!(envmnt::is_equal(
        "MY_ENV_VAR",
        "OPTIONAL VALUE"
    ));
}