Installation
Add the crate
[dependencies]
vld = "0.5"
Or with cargo:
cargo add vld
cargo add vld --features derive,openapi
The minimum supported Rust version of the core crate is 1.85 with every feature. Integration crates may need more; see MSRV.
Features
No feature is enabled by default. Everything below is additive.
| Feature | Enables | Extra dependencies |
|---|---|---|
derive | #[derive(Validate)] (guide) | vld-derive |
openapi | JsonSchema trait, json_schema(), to_openapi_document() (guide) | none |
diff | vld::diff::diff_schemas for breaking-change detection; implies openapi (guide) | none |
regex | vld::string().pattern(...), vld::rules::Pattern | regex-lite |
chrono | vld::chrono::{date, datetime, time} (guide) | chrono |
jiff | vld::jiff::{date, datetime, time} | jiff |
time | vld::time::{date, datetime, time} | time |
decimal | vld::decimal() (rust_decimal::Decimal) | rust_decimal |
net | vld::ip_network() (ipnet::IpNet) | ipnet |
file | vld::file() with size, extension and media-type checks | infer |
file-advanced | file plus sha256() / md5(), image dimensions, require_exif() | sha2, md-5, image, kamadak-exif |
string-advanced | url_strict(), uri(), uuid_v1/v4/v7(), phone_e164_strict(), semver_full() | url, uuid, phonenumber, semver |
The date features can be enabled together. vld::date(), vld::datetime() and vld::time_of_day() exist only when exactly one of them is on; with several, call the backend module (vld::chrono::date()). See Dates.
serialize and deserialize are deprecated no-ops kept for compatibility (serde support is always on). They will be removed in 0.6. The old std feature is gone.Typical setups
# Web API with OpenAPI docs and derive
vld = { version = "0.5", features = ["derive", "openapi"] }
vld-axum = "0.5"
# Config validation with dates
vld = { version = "0.5", features = ["chrono"] }
vld-config = "0.5" # config-rs; features = ["figment"] for figment
Prelude
Most code needs a single import:
use vld::prelude::*;
It brings in the VldSchema, VldParse and VldInput traits, the error types (VldError, ValidationIssue, IssueCode, PathSegment), the formatting helpers and every schema type. With openapi it also exports the JsonSchema trait.
The schema constructors are free functions: vld::string(), vld::number(), vld::array(...). They are not in the prelude, so call them with the vld:: prefix.