Skip to content

Commit 6509092

Browse files
committed
Add code example to std::os::getenv for unix.
1 parent d130acc commit 6509092

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/libstd/os.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,16 @@ pub fn env_as_bytes() -> Vec<(Vec<u8>,Vec<u8>)> {
277277
/// # Failure
278278
///
279279
/// Fails if `n` has any interior NULs.
280+
///
281+
/// # Example
282+
///
283+
/// ```rust
284+
/// let key = "HOME";
285+
/// match std::os::getenv(key) {
286+
/// Some(val) => println!("{}: {}", key, val),
287+
/// None => println!("{} is not defined in the environnement.", key)
288+
/// }
289+
/// ```
280290
pub fn getenv(n: &str) -> Option<String> {
281291
getenv_as_bytes(n).map(|v| str::from_utf8_lossy(v.as_slice()).to_string())
282292
}

0 commit comments

Comments
 (0)