from_env

Function from_env 

Source
pub fn from_env<'de, T>() -> Result<T>
where T: Deserialize<'de>,
Expand description

Deserialize an instance of T from the environment variables of the current process.

§Example

Assuming we have a TIMEOUT and HOST environment variable:

#[derive(serde::Deserialize, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
struct Config {
    timeout: u16,
    host: std::net::IpAddr,
}

let config: Config = de_env::from_env()?;

println!("{config:#?}");

§Errors

This conversion can fail if trying to deserialize unsupported types, or if T’s implementation of Deserialize decides that something is wrong with the data.