Expand description
§skp-validator
The most advanced, flexible and modular validation library for Rust.
§Features
- Declarative Validation: Use derive macros with powerful attributes
- 30+ Built-in Validators: email, url, ip, uuid, phone, credit_card, etc.
- Nested Validation: Automatic validation of nested structs
- Collection Validation: Dive into Vec, HashMap, Option
- Field Dependencies: Conditional validation based on other fields
- Field Transformations: uppercase, lowercase, trim
- Structured Errors: Nested, JSON-serializable error format
- Runtime JSON Validation: Validate JSON without deserialization
- i18n Support: Localized error messages
- Framework Adapters: Axum, Actix integration
§Quick Start
ⓘ
use skp_validator::Validate;
#[derive(Validate)]
struct User {
#[validate(required, length(min = 3, max = 50))]
name: String,
#[validate(required, email)]
email: String,
#[validate(range(min = 18, max = 120))]
age: Option<u32>,
#[validate(nested)]
address: Address,
#[validate(dive, length(min = 1, max = 20))]
tags: Vec<String>,
}
let user = User { /* ... */ };
match user.validate() {
Ok(()) => println!("Valid!"),
Err(errors) => println!("Errors: {}", errors),
}Re-exports§
pub use skp_validator_rules as rules;
Modules§
Structs§
- AnyRule
- Any rule - passes if any of the inner rules pass (OR logic).
- Composite
Rule - A composite rule that combines multiple rules.
- Field
Path - A path to a field in a nested structure.
- Validation
Collector - Helper for collecting multiple validation results
- Validation
Context - Context for validation operations.
- Validation
Context Builder - Builder for ValidationContext with custom context type
- Validation
Error - A single validation error with path, code, and message.
- Validation
Errors - Container for validation errors with nested structure support.
Enums§
- Error
Param - Parameter value for validation errors (supports multiple types)
- Field
Errors - Container for field-level errors, supporting nested structures.
- Path
Segment - A segment of a field path.
Traits§
- Rule
- Trait for individual validation rules.
- Transform
- Trait for field transformations.
- Validate
- Core validation trait for types that can be validated.
- Validate
Dive - Trait for collection validation (dive).
- Validate
Nested - Trait for nested struct validation.
- Validation
Result Ext - Extension trait for ValidationResult
Type Aliases§
- AllRule
- All rule - passes only if all inner rules pass (AND logic, same as CompositeRule).
- Validation
Result - Result type for validation operations.
Derive Macros§
- Validate
- Derive macro for implementing the Validate trait.