vld 0.6.1

Type-safe runtime validation library for Rust, inspired by Zod
Documentation

vld

crates.io docs.rs CI docs license: MIT

Type-safe runtime validation for Rust, inspired by Zod.

Describe the shape of your data once, parse untrusted input into typed Rust values, and get every problem back with its path and a stable error code. The same schemas produce JSON Schema / OpenAPI and plug into web frameworks, databases, queues, config and CLI crates.

Documentation: s00d.github.io/vld · API reference: docs.rs/vld

[dependencies]
vld = "0.5"
use vld::prelude::*;

vld::schema! {
    #[derive(Debug)]
    pub struct User {
        pub name: String => vld::string().trim().min(2).max(50),
        pub email: String => vld::string().email(),
        pub age: Option<u8> => vld::u8().min(18).optional(),
        pub tags: Vec<String> => vld::array(vld::string()).max_len(5).with_default(vec![]),
    }
}

fn main() {
    let user = User::parse(r#"{"name": " Ada ", "email": "ada@example.com"}"#).unwrap();
    assert_eq!(user.name, "Ada");

    let err = User::parse(r#"{"name": "A", "email": "nope", "age": 12}"#).unwrap_err();
    assert_eq!(err.issues.len(), 3); // every issue, not just the first
    println!("{err}");
    // .name: String must be at least 2 characters, received "A"
    // .email: Invalid email address, received "nope"
    // .age: Number must be at least 18, received 12
}

Features

  • Schemas as values: strings with 40+ formats, exact sized integers, floats, dates (chrono, jiff or time), collections, tuples, unions, discriminated unions, refinements, transforms, recursive schemas.
  • Typed structs with vld::schema! or #[derive(Validate)] (feature derive), serde renames, lenient parsing.
  • Errors you can use: typed IssueCodes with stable keys, paths, received values, custom messages, flatten / treeify / prettify, bundled English, Russian, German and Spanish messages.
  • JSON Schema and OpenAPI 3.1 from the same schemas (feature openapi), plus breaking-change detection (feature diff).
  • Small core: only serde and serde_json by default; heavier validators are opt-in features.
  • Integration crates for 10 web frameworks, OpenAPI tools, databases, queues, config, CLI and UI, with one error format and safe defaults (2 MiB body limits, 415 / 422 handling).

Crates

Crate Purpose Docs
vld Core: schemas, macros, errors, i18n, JSON Schema guide · api
vld-derive #[derive(Validate)] (use through vld's derive feature) guide · api
Web
vld-axum Axum extractors guide · api
vld-actix Actix Web extractors guide · api
vld-ntex ntex 3 / 4 extractors guide · api
vld-poem Poem extractors guide · api
vld-rama Rama extractors and validation layer guide · api
vld-rocket Rocket data guards and JSON catchers guide · api
vld-salvo Salvo extractors guide · api
vld-tower Tower layer for any Tower-based server guide · api
vld-warp Warp filters guide · api
vld-tonic tonic gRPC messages and metadata guide · api
OpenAPI and JSON Schema
vld-utoipa utoipa ToSchema / IntoParams from vld schemas guide · api
vld-schemars Two-way bridge with schemars guide · api
vld-aide aide (OpenAPI for axum) guide · api
Codegen and test data
vld-ts Zod / Valibot TypeScript from vld schemas guide · api
vld-fake Fake data that satisfies a schema guide · api
Databases
vld-sqlx SQLx column wrappers and pre-write checks guide · api
vld-diesel Diesel column wrappers guide · api
vld-sea SeaORM ActiveModel validation guide · api
vld-surrealdb SurrealDB document validation guide · api
Messaging
vld-redis Validated Redis values (sync and async) guide · api
vld-lapin Validated RabbitMQ payloads guide · api
Config and CLI
vld-config config-rs / figment validation guide · api
vld-clap clap argument validation guide · api
UI
vld-dioxus Shared validation for Dioxus server and WASM guide · api
vld-leptos Shared validation for Leptos server and WASM guide · api
vld-tauri Tauri command and event payloads guide · api
Shared
vld-http-common HTTP helpers shared by the web crates guide · api
vld-integration-common DB / form helpers shared by the integration crates guide · api

Minimum supported Rust version

The core crate needs Rust 1.85 with every feature. Some integration features need a newer compiler; see MSRV.md.

Contributing

See the contributing guide and the changelog. Upgrading from 0.4: migration guide.

License

MIT