pub fn from_env_prefixed<'de, T>(prefix: &str) -> Result<T>where
T: Deserialize<'de>,Expand description
Deserialize an instance of T from the environment variables of the current process with the
specified prefix.
§Example
Assuming we have a PREFIX_TIMEOUT and PREFIX_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_prefixed("PREFIX_")?;
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.