pub struct Validator { /* private fields */ }Expand description
Accumulates FieldErrors; call finish at the end
Implementations§
Source§impl Validator
impl Validator
pub fn new() -> Self
Sourcepub fn error(&mut self, field: &str, message: impl Into<String>) -> &mut Self
pub fn error(&mut self, field: &str, message: impl Into<String>) -> &mut Self
Record an error for field
Sourcepub fn check(
&mut self,
condition: bool,
field: &str,
message: impl Into<String>,
) -> &mut Self
pub fn check( &mut self, condition: bool, field: &str, message: impl Into<String>, ) -> &mut Self
Record message for field unless condition holds
Sourcepub fn non_empty(&mut self, field: &str, value: &str) -> &mut Self
pub fn non_empty(&mut self, field: &str, value: &str) -> &mut Self
Text that is not empty after trimming
Sourcepub fn len_between(
&mut self,
field: &str,
value: &str,
min: usize,
max: usize,
) -> &mut Self
pub fn len_between( &mut self, field: &str, value: &str, min: usize, max: usize, ) -> &mut Self
Length in characters (not bytes) within min..=max
Sourcepub fn range<T: PartialOrd + Display>(
&mut self,
field: &str,
value: T,
min: T,
max: T,
) -> &mut Self
pub fn range<T: PartialOrd + Display>( &mut self, field: &str, value: T, min: T, max: T, ) -> &mut Self
Value within min..=max
Sourcepub fn email(&mut self, field: &str, value: &str) -> &mut Self
pub fn email(&mut self, field: &str, value: &str) -> &mut Self
Simple e-mail shape check: one @, text on both sides, a dot in the
domain, no whitespace. Deliverability is only proven by sending mail.
pub fn is_valid(&self) -> bool
Sourcepub fn finish(self) -> Result<()>
pub fn finish(self) -> Result<()>
Ok(()) without errors, otherwise Error::Validation (HTTP 422)
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