pub fn get_optional<K: AsRef<OsStr>, T: FromStr>(key: K) -> Option<T>
Expand description
Get the value of the environment variable key
as T
.
If the variable is not set or cannot be parsed, it returns None
.
ยงExample
use std::env;
use std::str::FromStr;
use better_config_core::utils::env::get_optional;
let value: Option<u32> = get_optional("MY_ENV_VAR");
match value {
Some(v) => println!("Value: {}", v),
None => println!("Variable not set or cannot be parsed"),
}