Crates.io | envir |
lib.rs | envir |
version | |
source | src |
created_at | 2022-07-22 10:39:23.332073 |
updated_at | 2024-12-07 13:44:33.671532 |
description | Deserialize/serialize struct from/to env |
homepage | |
repository | https://github.com/sanpii/envir |
max_upload_size | |
id | 630676 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A toolbox to deal with your environment.
Without feature, this crate provides simple functions to retreive the value of an environment variable:
get
to retreive as string;parse
to 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.
The dotenv
feature adds an eponyme function to load .env
file.
The logger
feature adds logger configured via environment variables.
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.