Runtime validation for Rust, the Zod way
vld describes the shape of your data once and checks untrusted input against it: JSON bodies, query strings, config files, database rows. Errors list every problem with its path, and the same schema produces OpenAPI.
What you get
Two minutes to the first parse
Add the crate, describe a struct and call parse(). Invalid input returns a VldError with every issue, not just the first.
Cargo.toml
[dependencies]
vld = { version = "0.5", features = ["derive", "openapi"] }
main.rs
use vld::prelude::*;
vld::schema! {
#[derive(Debug)]
pub struct User {
pub name: String => vld::string().min(2).max(50),
pub email: String => vld::string().email(),
pub age: Option<i64> => vld::number().int().gte(18).optional(),
}
}
let user = User::parse(r#"{"name": "Alex", "email": "alex@example.com"}"#)?;
assert_eq!(user.age, None);