1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! # modo::validate
//!
//! Input validation for request data.
//!
//! Provides:
//! - [`Validator`] — fluent builder that collects per-field validation errors
//! - [`ValidationError`] — per-field error collection; converts into [`crate::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 public items ([`Validate`], [`ValidationError`], [`Validator`])
//! are re-exported from [`crate::prelude`].
//!
//! ## Quick start
//!
//! ```rust,no_run
//! 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()
//! }
//! }
//! ```
pub use ValidationError;
pub use Validate;
pub use Validator;