vs Validator Crate
Feature comparison
Section titled “Feature comparison”| Feature | zod-rs | validator |
|---|---|---|
| Schema definition | Derive macro with attributes | Struct attributes only |
| Runtime flexibility | Dynamic schema creation | Compile-time only |
| Error messages | Detailed with full path context | Basic field-level errors |
| JSON integration | Built-in JSON validation/parsing | Manual serde integration |
| Nested validation | Automatic nested struct support | Manual implementation |
| Schema reuse | Composable and reusable schemas | Struct-bound validation |
| Type safety | Full type inference | Limited type information |
| Extensibility | Custom validators and schemas | Custom validation functions |
| Framework integration | Built-in Axum support | Manual integration |
| i18n | Built-in localized error messages | No i18n support |
Migration guide
Section titled “Migration guide”Before: validator crate
Section titled “Before: validator crate”use validator::{Validate, ValidationError};
#[derive(Validate)]struct User { #[validate(length(min = 3, max = 20))] username: String,
#[validate(email)] email: String,
#[validate(range(min = 13, max = 120))] age: u32,}After: zod-rs
Section titled “After: zod-rs”use zod_rs::prelude::*;
#[derive(ZodSchema)]struct User { #[zod(min_length(3), max_length(20))] username: String,
#[zod(email)] email: String,
#[zod(min(13.0), max(120.0), int)] age: u32,}What you gain
Section titled “What you gain”Validate and parse in one step
Section titled “Validate and parse in one step”// validator: validate then manually deserializelet user = User { ... };user.validate()?;
// zod-rs: validate and deserialize from JSON in one calllet user = User::validate_and_parse(&json_data)?;Parse from JSON strings directly
Section titled “Parse from JSON strings directly”let user = User::from_json(r#"{"username":"alice","email":"alice@example.com","age":25}"#)?;Reusable schemas
Section titled “Reusable schemas”// Create a schema once, use it many timeslet schema = User::schema();let is_valid = schema.validate(&data).is_ok();Dynamic schema creation
Section titled “Dynamic schema creation”// Build schemas at runtime — not possible with validatorlet schema = object() .field("name", string().min(2)) .field("email", string().email());Full path error messages
Section titled “Full path error messages”// validator: "email: Invalid email"// zod-rs: "user.profile.email: Invalid email address"