pub fn from_iter<'de, T>(
iter: impl Iterator<Item = (impl Into<Key<'de>>, impl Into<Value<'de>>)>,
) -> Result<T>where
T: Deserialize<'de>,Expand description
Deserialize an instance of T from an iterator of key-value tuple.
This is intended to be used when you wish to perform some operation, such as mapping or
filtering, on the iterator returned by std::env::vars() or std::env::vars_os().
§Example
#[derive(serde::Deserialize, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
struct Config {
timeout: u16,
host: std::net::IpAddr,
}
let vars = std::env::vars_os().filter(|(name, _value)| name == "TIMEOUT" || name == "HOST");
let config: Config = de_env::from_iter(vars)?;
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.
§Iterator Items
The items must be a tuple of length 2, where the first element is the key and the second the value. The elements may be of the following types: