pub struct ValidationError {
pub errors: Vec<FieldValidationError>,
}Expand description
Validation error for field-level and model-level validation.
Fields§
§errors: Vec<FieldValidationError>The errors grouped by field name (or “_model” for model-level)
Implementations§
Source§impl ValidationError
impl ValidationError
Sourcepub fn add(
&mut self,
field: impl Into<String>,
kind: ValidationErrorKind,
message: impl Into<String>,
)
pub fn add( &mut self, field: impl Into<String>, kind: ValidationErrorKind, message: impl Into<String>, )
Add a field validation error.
Sourcepub fn add_min(
&mut self,
field: impl Into<String>,
min: impl Display,
actual: impl Display,
)
pub fn add_min( &mut self, field: impl Into<String>, min: impl Display, actual: impl Display, )
Add a min value error.
Sourcepub fn add_max(
&mut self,
field: impl Into<String>,
max: impl Display,
actual: impl Display,
)
pub fn add_max( &mut self, field: impl Into<String>, max: impl Display, actual: impl Display, )
Add a max value error.
Sourcepub fn add_multiple_of(
&mut self,
field: impl Into<String>,
divisor: impl Display,
actual: impl Display,
)
pub fn add_multiple_of( &mut self, field: impl Into<String>, divisor: impl Display, actual: impl Display, )
Add a multiple_of error.
Used when a numeric value is not a multiple of the specified divisor.
Sourcepub fn add_min_items(
&mut self,
field: impl Into<String>,
min: usize,
actual: usize,
)
pub fn add_min_items( &mut self, field: impl Into<String>, min: usize, actual: usize, )
Add a min_items error for collections.
Used when a collection has fewer items than the minimum required.
Sourcepub fn add_max_items(
&mut self,
field: impl Into<String>,
max: usize,
actual: usize,
)
pub fn add_max_items( &mut self, field: impl Into<String>, max: usize, actual: usize, )
Add a max_items error for collections.
Used when a collection has more items than the maximum allowed.
Sourcepub fn add_unique_items(
&mut self,
field: impl Into<String>,
duplicate_count: usize,
)
pub fn add_unique_items( &mut self, field: impl Into<String>, duplicate_count: usize, )
Add a unique_items error for collections.
Used when a collection contains duplicate items.
Sourcepub fn add_min_length(
&mut self,
field: impl Into<String>,
min: usize,
actual: usize,
)
pub fn add_min_length( &mut self, field: impl Into<String>, min: usize, actual: usize, )
Add a min length error.
Sourcepub fn add_max_length(
&mut self,
field: impl Into<String>,
max: usize,
actual: usize,
)
pub fn add_max_length( &mut self, field: impl Into<String>, max: usize, actual: usize, )
Add a max length error.
Sourcepub fn add_pattern(&mut self, field: impl Into<String>, pattern: &str)
pub fn add_pattern(&mut self, field: impl Into<String>, pattern: &str)
Add a pattern match error.
Sourcepub fn add_required(&mut self, field: impl Into<String>)
pub fn add_required(&mut self, field: impl Into<String>)
Add a required field error.
Sourcepub fn add_custom(
&mut self,
field: impl Into<String>,
message: impl Into<String>,
)
pub fn add_custom( &mut self, field: impl Into<String>, message: impl Into<String>, )
Add a custom validation error.
Sourcepub fn add_model_error(&mut self, message: impl Into<String>)
pub fn add_model_error(&mut self, message: impl Into<String>)
Add a model-level validation error.
Model-level validators check cross-field constraints or validate the entire model state. The error is recorded with field “model”.
Sourcepub fn add_credit_card(&mut self, field: impl Into<String>)
pub fn add_credit_card(&mut self, field: impl Into<String>)
Add a credit card validation error.
Sourcepub fn into_result(self) -> Result<(), Self>
pub fn into_result(self) -> Result<(), Self>
Convert to Result, returning Ok(()) if no errors, Err(self) otherwise.
Trait Implementations§
Source§impl Clone for ValidationError
impl Clone for ValidationError
Source§fn clone(&self) -> ValidationError
fn clone(&self) -> ValidationError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ValidationError
impl Debug for ValidationError
Source§impl Default for ValidationError
impl Default for ValidationError
Source§impl Display for ValidationError
impl Display for ValidationError
Source§impl Error for ValidationError
impl Error for ValidationError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()