Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Rust

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".

use std::env;
let foo = env::var("FOO").unwrap_or("none".to_string());
use std::env;
let foo = match env::var("FOO") {
    Ok(val) => val,
    Err(_e) => "none".to_string(),
};
use std::env;
if let Ok(tnt_root) = env::var("TNT_ROOT") {
     //
}
use std::env;
let foo = match env::var("FOO") {
    Ok(val) => val,
    Err(_e) => "none".to_string(),
};
with Ada.Environment_Variables;
Foo : constant String :=
      Ada.Environment_Variables.Value (Name    => "FOO",
                                       Default => "none");

New implementation...
< >
tkoenig