vld-derive 0.1.0

Derive macro for the vld validation library
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 22.17 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 308.61 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • s00d/vld
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • s00d

Crates.io docs.rs License Platform GitHub issues GitHub stars

vld-derive

Derive macro for the vld validation library.

Overview

Provides #[derive(Validate)] — a procedural macro that generates validate() and is_valid() methods for your structs based on #[vld(...)] field attributes.

This crate is not meant to be used directly. Enable the derive feature on the vld crate instead:

[dependencies]
vld = { version = "0.1", features = ["derive"] }

Quick start

use vld::prelude::*;
use vld::Validate;

#[derive(Validate)]
struct User {
    #[vld(string().min(2).max(50))]
    name: String,
    #[vld(number().int().min(0))]
    age: i64,
    #[vld(string().email())]
    email: String,
}

Serde rename support

The macro automatically respects #[serde(rename)] and #[serde(rename_all)] attributes to determine the JSON field names used during validation:

use vld::prelude::*;
use vld::Validate;
use serde::Deserialize;

#[derive(Validate, Deserialize)]
#[serde(rename_all = "camelCase")]
struct ApiRequest {
    #[vld(string().min(1))]
    first_name: String,
    #[vld(string().email())]
    email_address: String,
}

This will expect JSON keys firstName and emailAddress.

Examples

See the playground example for a complete usage demo, including #[derive(Validate)]:

cargo run -p playground

License

MIT