vld-config
Validate configuration files (TOML, YAML, JSON, ENV) at load time using vld schemas. Supports both config-rs and figment.
Installation
[]
= "0.1"
= "0.1" # config-rs backend (default)
# vld-config = { version = "0.1", features = ["figment"] } # figment backend
# vld-config = { version = "0.1", features = ["config-rs", "figment"] } # both
Features
| Feature | Default | Description |
|---|---|---|
config-rs |
yes | config backend — from_config(), from_builder() |
figment |
no | figment backend — from_figment() |
Quick Start (config-rs)
use *;
schema!
let config = builder
.add_source
.add_source
.build
.unwrap;
let settings: AppSettings = from_config.unwrap;
println!;
Quick Start (figment)
use from_figment;
schema!
let figment = new
.merge
.merge;
let settings: AppSettings = from_figment.unwrap;
API
| Function | Backend | Description |
|---|---|---|
from_config(&Config) |
config-rs | Validate a built Config |
from_builder(ConfigBuilder) |
config-rs | Build and validate in one step |
from_figment(&Figment) |
figment | Validate a Figment |
from_value(&Value) |
— | Validate raw serde_json::Value |
All functions return Result<T, VldConfigError> where T: VldParse (implemented by vld::schema!).
Error Handling
match
Running Examples
# config-rs
# figment
License
MIT