Skip to main content

Crate vld

Crate vld 

Source
Expand description

§vld — Type-safe runtime validation for Rust

vld is a validation library inspired by Zod that combines schema definition with type-safe parsing.

§Quick Start

use vld::prelude::*;

// Define a validated struct
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(),
    }
}

// Parse from JSON string
let user = User::parse(r#"{"name": "Alex", "email": "alex@example.com"}"#).unwrap();
assert_eq!(user.name, "Alex");
assert_eq!(user.age, None);

Modules§

collections
combinators
error
format
i18n
Internationalization (i18n) support for validation error messages.
input
modifiers
object
prelude
Common imports for working with vld.
primitives
schema

Macros§

impl_default
Generate impl Default for a struct created by schema!.
impl_rules
Attach validation rules to an existing struct.
impl_validate_fields
Generate validate_fields() and parse_lenient() methods for a struct previously defined with schema!.
nested
Create a named nested schema with $ref generation and full JSON Schema.
schema
Define a validated struct with field-level schemas.
schema_validated
Combined macro: generates the struct, parse(), and validate_fields() / parse_lenient() in a single declaration — no need to repeat field schemas.
union
Create a union schema from 2 or more schemas.

Functions§

any
Create a schema that accepts any JSON value.
array
Create an array validation schema.
boolean
Create a boolean validation schema.
bytes
Create a bytes validation schema (Vec<u8>).
custom
Create a schema from a custom validation function.
discriminated_union
Create a discriminated union schema.
duration
Create a duration validation schema (std::time::Duration).
enumeration
Create a string enum schema. Validates against a fixed set of values.
intersection
Create an intersection of two schemas (input must satisfy both).
json_value
Create a raw JSON value schema with shape constraints.
lazy
Create a lazy schema for recursive data structures.
literal
Create a literal value schema. Validates exact match.
map
Create a Map schema. Validates [[key, value], ...] arrays into HashMap.
nested
Create a schema for nested/composed structs.
nested_named
number
Create a number validation schema (f64).
object
Create a dynamic object validation schema.
path
Create a path validation schema (std::path::PathBuf).
preprocess
Preprocess the JSON value before passing it to a schema.
record
Create a record (dictionary) schema. All values validated by the given schema.
set
Create a Set schema. Validates arrays into HashSet (unique elements).
socket_addr
Create a socket address schema (std::net::SocketAddr).
string
Create a string validation schema.
union
Create a union of two schemas. Returns Either<A, B>.
union3
Create a union of three schemas. Returns Either3<A, B, C>.