potenv
A Rust implementation of the POSIX-compliant dotenv file format specification.
Usage
Load environment variables from a .env file in the current working directory:
load.expect;
For convenience, an iterator over the loaded variables is returned:
let vars = load.unwrap;
for in vars
If you just want to evaluate the dotenv files without loading them into the environment, use the following:
use Potenv;
let vars = default
.evaluate
.unwrap;
By default, environment variables take precedence over variables defined in a dotenv file.
When this is not the desired behaviour, you can use the following:
use Potenv;
let vars = default
.override_env
.load
.unwrap;
If you don't want to read from and/or write to the process environment, you can implement the [env::EnvProvider] trait.
For example, this is how to frobnicate all variables:
use ;
;
let vars = new
.evaluate
.unwrap;
for in vars
If you just want to mock the environment in unit-tests,
the [env::EnvProvider] trait is implemented for HashMap<String, String>:
use HashMap;
use Potenv;
let mut mock = new;
mock.insert;
let vars = new
.evaluate
.unwrap;