envir
A toolbox to deal with your environment.
Basics
Without feature, this crate provide simple functions to retreive the value of an environment variable:
getto retreive as string;parseto directly parse the value as a desired type.
The try_ version of theire functions return None if the variable doens’t
exist when get and parse return an Error::Missing error.
In addition this crate provide a set function, like std::env::set_var but
works for all types implement ToString.
Finally, a collect function to retreive all environment variables in a easy to
print collection.
dotenv
The dotenv feature adds an eponyme function to load .env file.
serde
The serde feature adds macro to deserialize struct from env:
#[derive(envir::Deserialize)]
struct Config {
}
let config = envir::from_env()?;
// or
let config = Config::from_env()?;
And serialize to env:
#[derive(envir::Serialize, Default)]
struct Config {
}
let config = Config::default();
config.export();
The extrapolation feature allows environment variables replacement in the
default macro attribute:
#[derive(envir::Deserialize)]
struct Config {
#[envir(defaut = "/home/${USER}")]
home: String,
}
You can read the envir_derive crate documentation for more informations.