Expand description
§modo::validate
Input validation for request data.
Always available (no feature flag required).
Provides:
Validator— fluent builder that collects per-field validation errorsValidationError— per-field error collection; converts intocrate::Error(HTTP 422)Validate— trait for types that validate themselves
Field rules are applied through a FieldValidator obtained inside the
Validator::field closure. String rules require T: AsRef<str>; numeric
rules require T: PartialOrd + Display.
ValidationError converts automatically into crate::Error via the
From impl, producing an HTTP 422 Unprocessable Entity response whose
details field contains the per-field error map.
All three types are re-exported at the crate root as crate::Validate,
crate::ValidationError, and crate::Validator.
§Quick start
use modo::validate::{Validate, ValidationError, Validator};
struct CreateUser {
name: String,
email: String,
age: u32,
}
impl Validate for CreateUser {
fn validate(&self) -> Result<(), ValidationError> {
Validator::new()
.field("name", &self.name, |f| {
f.required().min_length(2).max_length(100)
})
.field("email", &self.email, |f| f.required().email())
.field("age", &self.age, |f| f.range(18..=120))
.check()
}
}Structs§
- Validation
Error - A collection of per-field validation errors.
- Validator
- A builder that collects validation errors across multiple fields.
Traits§
- Validate
- Types that can validate their own fields.