Envro
Env vars for Rust: validate with a composable rule set, load .env into std::env, and optionally derive a typed Config.
Features
- Validate env vars against a
Schemaof composable rules — works on anyHashMap, a.envfile, or the live process environment - Load a
.envinto the process with an explicit override policy, or parse it to a map with no side effects - Derive a typed
Configwith#[derive(Envro)]— field types are coerce targets;#[envro(...)]attrs are the rules; values still load at runtime - Compose derived values with
${VAR}substitution, then validate each part - Small
.envdialect — comments, quotes, multiline, duplicate keys rejected
Getting started
Typed app config
Typical service setup: optional .env for local dev, then validate and coerce the process environment into a struct.
use env;
use ;
On failure, EnvroError::Validation lists every failing rule:
// example/src/bin/getting_started_error.rs — cargo run --bin getting_started_error
match from_dotenv
Real-world: CD / process env
In CI/CD and containers you get flat process env vars — not .env substitution. Validate each knob, then compose derived values in Rust:
use ;
Runnable version: cd example && cargo run --bin example.
${VAR} expansion is a .env-file feature only — see docs/dotenv-format.md.
Without derive
Same rules as a hand-written Schema when you only need validation (maps, tests, no struct):
use *;
let schema = new
.field
.field;
validate_env?;
// or: load_dotenv_validated(&path, &schema)?; validate(&vars, &schema)?;
Documentation
| Doc | Contents |
|---|---|
| docs/api.md | Public APIs and types (functions, Schema / Field, derive) |
| docs/validation.md | Rule reference, semantics, error inspection |
| docs/dotenv-format.md | .env dialect, ${VAR} substitution, valid/invalid rows |
| docs/comparison.md | Comparison with dotenvy, dotenv-ng, and related crates |
| docs.rs/envro | Generated rustdoc |
Out of scope
- No multi-file layering — one path per call (CUE on inheritance, Angular LIFT Flat)
- No macros that bake env values into the binary —
#[derive(Envro)]encodes types and rules only; values always load at runtime
TODO
- optional, default values
- encryption
License
MIT © 2024-2026 Simone Sanfratello