Skip to main content

var

Function var 

Source
pub fn var<K: AsRef<OsStr>>(key: K) -> Result<String>
Expand description

Get the value for an environment variable.

Automatically loads .env on first call (if present and not yet loaded). Values are read from the current process environment, not directly from the .env file — so any value set by a previous caller or the shell is visible.

§Errors

Returns Error::Env if the variable contains non-unicode data.

§Examples

let value = dotenv::var("HOME").unwrap();
println!("{}", value);