Skip to content

Commit 85adc09

Browse files
committed
Improve documentation on std::os::env.
1 parent f377dfe commit 85adc09

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/libstd/os.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,20 @@ fn with_env_lock<T>(f: || -> T) -> T {
206206
}
207207
}
208208

209-
/// Returns a vector of (variable, value) pairs for all the environment
210-
/// variables of the current process.
209+
/// Returns a vector of (variable, value) pairs as a Vec<(String, String)>,
210+
/// for all the environment variables of the current process.
211211
///
212212
/// Invalid UTF-8 bytes are replaced with \uFFFD. See `str::from_utf8_lossy()`
213213
/// for details.
214+
///
215+
/// # Example
216+
///
217+
/// ```rust
218+
/// // We will iterate through the references to the element returned by std::os::env();
219+
/// for &(ref key, ref value) in std::os::env().iter() {
220+
/// println!("'{}': '{}'", key, value );
221+
/// }
222+
/// ```
214223
pub fn env() -> Vec<(String,String)> {
215224
env_as_bytes().move_iter().map(|(k,v)| {
216225
let k = str::from_utf8_lossy(k.as_slice()).to_string();

0 commit comments

Comments
 (0)