Expand description
§envir
A toolbox to deal with your environment.
§Basics
Without feature, this crate provides 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 these functions return None if the variable doens’t
exist when get and parse return the 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.
§logger
The logger feature adds logger configured via environment variables.
§serde
The serde feature adds macro to deserialize struct from env:
use envir::Deserialize;
#[derive(envir::Deserialize)]
struct Config {
}
fn main() -> envir::Result {
let config: Config = envir::from_env()?;
// or
let config = Config::from_env()?;
Ok(())
}And serialize to env:
use envir::Serialize;
#[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(default = "/home/${USER}")]
home: String,
}You can read the envir_derive crate documentation for more informations.
Modules§
- logger
env_loggerortracing
Enums§
Traits§
- Deserialize
serde - Serialize
serde
Functions§
- collect
- Retreives all environment variables as an easy printable form.
- dotenv
dotenv - Loads the .env files.
- from
serde - from_
env serde - from_
path dotenv - Loads environment variables from the specified path.
- get
- Likes
try_getbut returns acrate::Error::Missingif the variable isn’t set. - init
- Loads the .env file and initializes the logger.
- parse
- Likes
try_parsebut returns acrate::Error::Missingif the variable isn’t set. - set
- Sets the environment variable
keyto thevalue. - try_get
- Gets the environment variable
key. This returns acrate::Error::Unicodeif the variable value isn’t valid unicode. - try_
init - Attempts to load the .env file and to initialize the logger.
- try_
parse - Likes
try_getbut directly parses the variable value in desiredTtype.