Validator

Derive-macro struct validation for Rust, covering email, URL, length, range, and custom rules

Library
Cargo
v0.21.0
2,519 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
54 /100 Fair
Development Activity 40
Maintenance 16
Community 60
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
78 /100 Good
Architecture 80
Code Quality 82
Innovation 72
Learning Curve 78

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/Field error 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 typed context argument for dependency injection (e.g. a database handle)
  • Per-rule message and code overrides for internationalized, application-specific error text
  • An optional card feature (via card-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 SignupData struct containing a Vec<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 5 apps in this directory

Go
32%
Apache 2.0

CubeSandbox

AI Agents · Developer Tools · Security

12,728

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.

View details
82
Repo Health
88
Technical
63
Dependency
Built with
Go 32%
Rust 26%
C 22%
Updated 1 weeks ago
Rust
37%
Other

Hook0

Devops

1,491

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.

View details
82
Repo Health
82
Technical
69
Dependency
Built with
Rust 37%
TypeScript 12%
Updated 1 weeks ago
Rust
47%
MIT

Svix

Automation · Developer Tools

3,423

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.

View details
90
Repo Health
77
Technical
67
Dependency
Built with
Rust 47%
C# 15%
Updated 1 weeks ago
Rust
93%
Other

Tabby

AI Code Assistants

33,892

Self-hosted AI coding assistant — run GitHub Copilot-grade code completion on your own hardware with no cloud dependency.

View details
58
Repo Health
78
Technical
61
Dependency
Built with
Rust 93%
Updated 3 months ago
Rust
64%
Apache 2.0

Temps

Analytics · Devops · Monitoring

801

A self-hosted Rust PaaS that replaces Vercel, Sentry, PostHog, Pingdom, Resend, and E2B with one binary — plus 440+ CLI operations agents like Claude Code can drive directly.

View details
81
Repo Health
86
Technical
70
Dependency
Built with
Rust 64%
TypeScript 34%
Updated 4 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers