4 releases
Uses new Rust 2024
| 0.1.7 | Feb 2, 2026 |
|---|---|
| 0.1.6 | Feb 1, 2026 |
| 0.1.5 | Jan 31, 2026 |
| 0.1.4 | Jan 31, 2026 |
#703 in Operating systems
38KB
657 lines
Envflag
A strict, zero-boilerplate environment variable manager with .env support and validation.
envflag enforces a disciplined approach to configuration: you must explicitly initialize the library (which loads .env files via dotenvy), and then query typed values through a validated builder API or simple convenience functions.
Features
- Strict Initialization: All queries panic if
init()has not been called — no silent misconfiguration. - Dotenv Support: Seamlessly loads
.envfiles upon initialization, or from a custom path. - Prefix Filtering: Keep only environment variables matching configured prefixes (e.g.
APP_,SVC_). - Validated Builder API: Chain
.default(),.validate(), and.get()for type-safe, validated lookups that returnResult. - Built-in Validators:
is_port,is_integer,is_positive_integer,is_positive_number,is_bool,is_non_empty,is_url,is_integer_in_range, and more. - Custom Validators: Pass any
Fn(&str) -> boolclosure as a validator. - Zero Boilerplate: No built-in logging or printing; you control how to display your config.
Usage Examples
Check the examples directory for runnable code:
- Basic Usage:
examples/basic.rs- Initialize and query with convenience API. - Validation:
examples/validation.rs- Chain validators on environment variables. - Prefix Filtering:
examples/prefixes.rs- Filter and scope variables by prefix. - Custom Init:
examples/custom_init.rs- Load from a specific.envfile path.
Installation
[dependencies]
envflag = { version = "0.1", features = ["full"] }
Feature Flags
| Feature | Description |
|---|---|
url |
Enables strict URL validation in is_url via the url crate (WHATWG URL Standard). |
regex |
Enables matches_regex validator via fancy-regex. |
tracing |
Enables optional tracing::warn on validation failures and parse fallbacks in convenience API. |
full |
Enables all features above. |
License
Released under the MIT License © 2026 Canmi
Dependencies
~0.2–3MB
~41K SLoC