pub struct Validator { /* private fields */ }Expand description
A builder that collects validation errors across multiple fields.
Call Validator::new (or Default::default) to start, chain
field calls for each input to validate, then call
check to obtain the result. Errors from all fields
are gathered before returning — no short-circuit.
§Example
use modo::validate::Validator;
let result = Validator::new()
.field("name", &"Alice".to_string(), |f| f.required().min_length(1))
.field("age", &25i32, |f| f.range(18..=120))
.check();Implementations§
Source§impl Validator
impl Validator
Sourcepub fn field<T>(
self,
name: &str,
value: &T,
f: impl FnOnce(FieldValidator<'_, T>) -> FieldValidator<'_, T>,
) -> Self
pub fn field<T>( self, name: &str, value: &T, f: impl FnOnce(FieldValidator<'_, T>) -> FieldValidator<'_, T>, ) -> Self
Validate a single field. The closure receives a FieldValidator and should
chain rule methods on it. Any rule failures are collected as errors for this field.
Works with any value type — string rules are available for T: AsRef<str>,
numeric rules for T: PartialOrd + Display.
Sourcepub fn check(self) -> Result<(), ValidationError>
pub fn check(self) -> Result<(), ValidationError>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Validator
impl RefUnwindSafe for Validator
impl Send for Validator
impl Sync for Validator
impl Unpin for Validator
impl UnsafeUnpin for Validator
impl UnwindSafe for Validator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more