Validator
Derive-macro struct validation for Rust, covering email, URL, length, range, and custom rules
Repository Health
Technical Analysis
Validator is a Rust crate that brings declarative, derive-macro-based validation to structs, inspired by Python’s marshmallow and Django’s validators. Instead of hand-writing imperative checks, you annotate struct fields with attributes like #[validate(email)], #[validate(length(min = 1, max = 10))], or #[validate(range(min = 18, max = 20))], and the validator_derive proc-macro generates a validate() method that returns a structured ValidationErrors map keyed by field name. It supports nested struct and vector validation, struct-level cross-field checks, custom validation functions with optional context arguments, and per-rule custom error messages and codes for i18n. The crate can also be used standalone (without the derive macro) by calling its validation functions directly.
What You Get
- Built-in validators: email, url, length, range, must_match, contains, does_not_contain, regex, credit_card, non_control_character, and required
- Nested validation for structs and vectors of structs, with
List/Struct/Fielderror variants that mirror the source shape - Struct-level
#[validate(schema(function = "..."))]for cross-field checks that run after per-field validation - Custom validators via
#[validate(custom(function = "..."))], including an optional typedcontextargument for dependency injection (e.g. a database handle) - Per-rule
messageandcodeoverrides for internationalized, application-specific error text - An optional
cardfeature (viacard-validate) for credit card number checks, kept out of the default build
Common Use Cases
- Validating deserialized API request bodies (paired with
serde::Deserialize) before they reach business logic - Enforcing signup/profile form constraints such as email format, username length, and age ranges
- Cross-field checks like password confirmation (
must_match) or category-dependent rules via struct-level validation - Composing validation across nested DTOs, e.g. a
SignupDatastruct containing aVec<Preference>that each need validating
Under The Hood
Architecture - The workspace splits into validator (the Validate/ValidateArgs traits, built-in validation functions in src/validation/*.rs, and error types in types.rs/traits.rs) and validator_derive (the proc-macro that parses #[validate(...)] attributes and generates the trait implementation), kept as separate crates so consumers can depend on just the runtime validators without the macro if desired. Tech Stack - Rust 2021 edition (MSRV 1.88), built on regex, url, and idna for format validators, serde/serde_derive/serde_json for error serialization, with card-validate and indexmap as opt-in features. Code Quality - The validator_derive_tests crate holds 20+ focused integration test files (one per validator plus nested/custom/schema/skip cases) alongside trybuild-style compile-pass/compile-fail fixtures for macro error messages; the core crates carry MIT licensing and a CI badge for cross-version testing. API Design - The attribute-based API keeps validation declarations colocated with struct fields and close to serde’s own attribute style, so most projects add one derive and a handful of attributes to get structured, field-keyed errors with no boilerplate glue code.
Used by 4 apps in this directory
CubeSandbox
Developer Tools · Security · AI Agents
Instant, concurrent, hardware-isolated MicroVM sandboxes for AI agents — E2B-API compatible, sub-60ms cold starts, and a built-in zero-trust egress proxy, all self-hostable at scale.
Hook0
Devops
Open-source Webhooks-as-a-Service: deliver events to your users with auto-retry, signed payloads, and a real-time subscriber dashboard — all without building the infrastructure yourself.
Svix
Developer Tools · Automation
Open source, self-hostable webhook infrastructure that handles delivery, retries, HMAC signing, and multi-tenant event management so you never have to build a webhooks system from scratch.
Tabby
AI Code Assistants
Self-hosted AI coding assistant — run GitHub Copilot-grade code completion on your own hardware with no cloud dependency.