Logo

Programming-Idioms

History of Idiom 205 > diff from v23 to v24

Edit summary for version 24 by Yann:
New Rust implementation by user [Yann]

Version 23

2019-10-07, 20:09:03

Version 24

2019-10-19, 23:07:21

Idiom #205 Get an environment variable

Read an environment variable with the name "FOO" and assign it to the string variable foo. If it does not exist or if the system does not support environment variables, assign a value of "none".

Idiom #205 Get an environment variable

Read an environment variable with the name "FOO" and assign it to the string variable foo. If it does not exist or if the system does not support environment variables, assign a value of "none".

Extra Keywords
envvar os system
Extra Keywords
envvar os system
Imports
use std::env;
Code
let key = "FOO";
match env::var(key) {
    Ok(val) => println!("{}: {:?}", key, val),
    Err(e) => println!("couldn't interpret {}: {}", key, e),
}
Doc URL
https://doc.rust-lang.org/1.31.0/std/env/fn.var.html
Origin
https://doc.rust-lang.org/1.31.0/std/env/fn.var.html