3 releases
| 0.1.2 | Dec 30, 2025 |
|---|---|
| 0.1.1 | Dec 29, 2025 |
| 0.1.0 | Dec 27, 2025 |
#1574 in Web programming
Used in armature-framework
2MB
41K
SLoC
armature-validation
Request validation for the Armature framework.
Features
- Derive Macro -
#[derive(Validate)]for structs - Built-in Rules - Email, URL, length, range, regex, etc.
- Custom Validators - Create your own validation rules
- Nested Validation - Validate nested structs
- Error Messages - Customizable error messages
Installation
[dependencies]
armature-validation = "0.1"
Quick Start
use armature_validation::{Validate, ValidationError};
#[derive(Validate)]
struct CreateUser {
#[validate(length(min = 3, max = 50))]
username: String,
#[validate(email)]
email: String,
#[validate(length(min = 8))]
password: String,
#[validate(range(min = 13, max = 120))]
age: u8,
}
fn create_user(data: CreateUser) -> Result<(), ValidationError> {
data.validate()?;
// Process valid data
Ok(())
}
Available Validators
| Validator | Description |
|---|---|
email |
Valid email address |
url |
Valid URL |
length(min, max) |
String length bounds |
range(min, max) |
Numeric range |
regex(pattern) |
Regex match |
required |
Non-empty value |
custom(fn) |
Custom function |
Custom Validators
fn validate_username(username: &str) -> Result<(), ValidationError> {
if username.contains(' ') {
return Err(ValidationError::new("No spaces allowed"));
}
Ok(())
}
#[derive(Validate)]
struct User {
#[validate(custom = "validate_username")]
username: String,
}
License
MIT OR Apache-2.0
Dependencies
~33–51MB
~1M SLoC