envigil
Keep vigil over your environment.
Load, parse, and validate environment variables with zero dependencies and first-class error reporting.
Why envigil?
std::env |
envy |
envconfig |
dotenvy |
figment |
config |
envigil | |
|---|---|---|---|---|---|---|---|
| Zero dependencies | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ |
| Typed parsing | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ |
| Semantic validation | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ |
| Multi-error reporting | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ |
| Secret redaction | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ |
.env file support |
❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ (feature) |
| Derive macro | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ (feature) |
| Layered config | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ |
| CLI args | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Async support | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ |
| MSRV | — | 1.60+ | — | 1.65+ | 1.70+ | 1.75+ | 1.85 |
| Actively maintained | ✅ | ⚠️ | ❌ | ✅ | ✅ | ✅ | 🆕 |
envigil is not a replacement for
figmentorconfig(layered providers, async, file formats). It is a lightweight alternative toenvy/envconfigfor those who need validation, multi-error reporting, and secret redaction without pulling in dependencies.
The core crate is std-only. No serde, no syn, no anyhow.
Proc-macro and .env support are opt-in feature flags.
Quick start
[]
= "0.1"
Builder API
use ;
use validate;
use Duration;
Derive API
[]
= { = "0.1", = ["derive"] }
use ;
use Duration;
Error output
All errors are collected and reported together:
environment configuration failed (2 errors)
environment variable 'APP_PORT' is required but not set
failed to parse 'APP_TIMEOUT_SECS': invalid number of seconds: invalid digit (received: "abc")
Validation
Built-in validators:
use validate;
new
.validate
new
.validate
.validate
new
.validate
Custom validators — any closure:
new
.validate_with
Or implement the trait:
use Validator;
;
Secret handling
Variables marked .secret() are stored as Secret<T>:
Debug/Displayprint[REDACTED]- Inner value accessible via
.expose() get::<String>()on a secret variable fails — you must useget::<Secret<String>>()
let url: & = cfg.get?;
let raw: &str = url.expose; // explicit opt-in
Parse helpers
use parse;
secs // Ok(Duration::from_secs(30))
millis // Ok(Duration::from_millis(500))
flag // Ok(true) — also: true/1/on, false/0/no/off
list // Ok(vec!["a", "b", "c"])
list_sep // Ok(vec!["x", "y"])
.env file support
[]
= { = "0.1", = ["dotenv"] }
let cfg = new
.dotenv // loads .env from CWD (optional)
.dotenv_path // or a specific path
.declare
.load?;
Real environment variables always take priority over .env
entries. Missing files are silently ignored.
Supported syntax:
# Comment
PORT=8080
NAME="hello world"
EMPTY=
Feature flags
| Feature | Default | Adds |
|---|---|---|
derive |
❌ | #[derive(EnvConfig)] (pulls envigil-derive) |
dotenv |
❌ | .env file loading (own parser, no external deps) |
With no features enabled, envigil has zero dependencies.
Minimum Supported Rust Version
1.85.0 (edition 2024). MSRV bumps come with a minor version bump and are noted in the changelog.