1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
use ;
use crate::;
use ;
/// Deserialize an instance of `T` from the environment variables of the current process.
///
/// # Example
///
/// Assuming we have a `TIMEOUT` and `HOST` environment variable:
///
/// ```rust
/// #[derive(serde::Deserialize, Debug)]
/// #[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// struct Config {
/// timeout: u16,
/// host: std::net::IpAddr,
/// }
///
/// # std::env::set_var("TIMEOUT", "12");
/// # std::env::set_var("HOST", "127.0.0.1");
/// let config: Config = de_env::from_env()?;
///
/// println!("{config:#?}");
/// # Ok::<(), de_env::Error>(())
/// ```
///
/// # 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.
///
/// [unsupported types]: crate#unsupported-types
/// 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:
///
/// ```rust
/// #[derive(serde::Deserialize, Debug)]
/// #[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// struct Config {
/// timeout: u16,
/// host: std::net::IpAddr,
/// }
///
/// # std::env::set_var("PREFIX_TIMEOUT", "12");
/// # std::env::set_var("PREFIX_HOST", "127.0.0.1");
/// let config: Config = de_env::from_env_prefixed("PREFIX_")?;
///
/// println!("{config:#?}");
/// # Ok::<(), de_env::Error>(())
/// ```
///
/// # 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.
///
/// [unsupported types]: crate#unsupported-types
/// 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
/// ```rust
/// #[derive(serde::Deserialize, Debug)]
/// #[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// struct Config {
/// timeout: u16,
/// host: std::net::IpAddr,
/// }
///
/// # std::env::set_var("TIMEOUT", "12");
/// # std::env::set_var("HOST", "127.0.0.1");
/// let vars = std::env::vars_os().filter(|(name, _value)| name == "TIMEOUT" || name == "HOST");
///
/// let config: Config = de_env::from_iter(vars)?;
///
/// println!("{config:#?}");
/// # Ok::<(), de_env::Error>(())
/// ```
///
/// # 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:
/// - [`OsString`](std::ffi::OsString)
/// - [`String`]
/// - [`Cow<str>`](std::borrow::Cow)
/// - [`Cow<OsStr>`](std::borrow::Cow)
/// - [`&OsStr`](std::ffi::OsStr)
/// - [`&str`]
///
/// [unsupported types]: crate#unsupported-types
;