| Crates.io | armature-validation |
| lib.rs | armature-validation |
| version | 0.1.2 |
| created_at | 2025-12-27 02:25:42.581223+00 |
| updated_at | 2025-12-30 22:49:11.085781+00 |
| description | Request validation for Armature handlers |
| homepage | https://pegasusheavy.github.io/armature |
| repository | https://github.com/pegasusheavy/armature |
| max_upload_size | |
| id | 2006586 |
| size | 91,119 |
Request validation for the Armature framework.
#[derive(Validate)] for structs[dependencies]
armature-validation = "0.1"
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(())
}
| 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 |
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,
}
MIT OR Apache-2.0