pub struct Validator { /* private fields */ }Expand description
Validator for collecting and running multiple validation rules.
Implementations§
Source§impl Validator
impl Validator
Sourcepub fn context(&self) -> &ValidationContext
pub fn context(&self) -> &ValidationContext
Get current validation context.
Sourcepub fn context_mut(&mut self) -> &mut ValidationContext
pub fn context_mut(&mut self) -> &mut ValidationContext
Get mutable validation context.
Sourcepub fn add_if(
&mut self,
condition: bool,
field: &str,
message: impl Into<String>,
)
pub fn add_if( &mut self, condition: bool, field: &str, message: impl Into<String>, )
Add error if condition is true.
Sourcepub fn validate_field<T, R>(&mut self, field: &str, value: &T, rule: &R)where
R: ValidationRule<T>,
pub fn validate_field<T, R>(&mut self, field: &str, value: &T, rule: &R)where
R: ValidationRule<T>,
Validate a value with a rule.
Sourcepub fn require_non_empty(&mut self, field: &str, value: &str)
pub fn require_non_empty(&mut self, field: &str, value: &str)
Validate a required string field is not empty.
Sourcepub fn require_positive<T: PartialOrd + Default + Display>(
&mut self,
field: &str,
value: T,
)
pub fn require_positive<T: PartialOrd + Default + Display>( &mut self, field: &str, value: T, )
Validate a numeric value is positive.
Sourcepub fn require_range<T: PartialOrd + Display + Copy>(
&mut self,
field: &str,
value: T,
min: T,
max: T,
)
pub fn require_range<T: PartialOrd + Display + Copy>( &mut self, field: &str, value: T, min: T, max: T, )
Validate a value is in a range.
Sourcepub fn validate_nested<F>(&mut self, field: &str, f: F)where
F: FnOnce(&mut Self),
pub fn validate_nested<F>(&mut self, field: &str, f: F)where
F: FnOnce(&mut Self),
Validate with a nested context.
Sourcepub fn has_errors(&self) -> bool
pub fn has_errors(&self) -> bool
Check if there are any errors.
Sourcepub fn errors(&self) -> &ValidationErrors
pub fn errors(&self) -> &ValidationErrors
Get the collected errors.
Sourcepub fn into_errors(self) -> ValidationErrors
pub fn into_errors(self) -> ValidationErrors
Consume and return the errors.
Sourcepub fn into_result(self) -> Result<()>
pub fn into_result(self) -> Result<()>
Convert to Result.
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