Getting started

Installation

Add vld to Cargo.toml and pick the features you need.

Add the crate

Cargo.toml
[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.

FeatureEnablesExtra dependencies
derive#[derive(Validate)] (guide)vld-derive
openapiJsonSchema trait, json_schema(), to_openapi_document() (guide)none
diffvld::diff::diff_schemas for breaking-change detection; implies openapi (guide)none
regexvld::string().pattern(...), vld::rules::Patternregex-lite
chronovld::chrono::{date, datetime, time} (guide)chrono
jiffvld::jiff::{date, datetime, time}jiff
timevld::time::{date, datetime, time}time
decimalvld::decimal() (rust_decimal::Decimal)rust_decimal
netvld::ip_network() (ipnet::IpNet)ipnet
filevld::file() with size, extension and media-type checksinfer
file-advancedfile plus sha256() / md5(), image dimensions, require_exif()sha2, md-5, image, kamadak-exif
string-advancedurl_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

Cargo.toml
# 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.