pub fn from_env<T: FromEnv>() -> Result<T>Expand description
Read T from the current process environment.
Examples found in repository?
examples/enum_config.rs (line 104)
102fn main() {
103 // Read from the process environment (falling back to the defaults).
104 match confroid::from_env::<Config>() {
105 Ok(config) => println!("from environment: {config:?}"),
106 Err(err) => eprintln!("config error: {err}"),
107 }
108
109 // A self-contained demonstration using explicit values:
110 let config: Config =
111 confroid::from_pairs([("LOG_LEVEL", "debug"), ("MODE", "cluster")]).expect("valid config");
112 println!("explicit: {config:?}");
113
114 let defaults: Config =
115 confroid::from_pairs(Vec::<(&str, &str)>::new()).expect("defaults are total");
116 println!("all defaults: {defaults:?}");
117}