pub struct ValidationErrors {
pub errors: Vec<ValidationError>,
pub fields: BTreeMap<String, FieldErrors>,
}Expand description
Container for validation errors with nested structure support.
§Example
use skp_validator_core::{ValidationErrors, ValidationError};
let mut errors = ValidationErrors::new();
errors.add_field_error("email", ValidationError::new("email", "email.invalid", "Invalid email"));
errors.add_field_error("name", ValidationError::new("name", "required", "Name is required"));
assert_eq!(errors.count(), 2);Fields§
§errors: Vec<ValidationError>Root-level errors (struct-wide validations)
fields: BTreeMap<String, FieldErrors>Field-level errors
Implementations§
Source§impl ValidationErrors
impl ValidationErrors
Sourcepub fn from_error(error: ValidationError) -> Self
pub fn from_error(error: ValidationError) -> Self
Create from a single error
Sourcepub fn add_root_error(&mut self, error: ValidationError)
pub fn add_root_error(&mut self, error: ValidationError)
Add a root-level error (not associated with a specific field)
Sourcepub fn add_field_error(
&mut self,
field: impl Into<String>,
error: ValidationError,
)
pub fn add_field_error( &mut self, field: impl Into<String>, error: ValidationError, )
Add a field-level error
Sourcepub fn add_nested_errors(
&mut self,
field: impl Into<String>,
errors: ValidationErrors,
)
pub fn add_nested_errors( &mut self, field: impl Into<String>, errors: ValidationErrors, )
Add nested struct errors
Sourcepub fn add_list_errors(
&mut self,
field: impl Into<String>,
errors: BTreeMap<usize, Box<ValidationErrors>>,
)
pub fn add_list_errors( &mut self, field: impl Into<String>, errors: BTreeMap<usize, Box<ValidationErrors>>, )
Add list item errors
Sourcepub fn add_map_errors(
&mut self,
field: impl Into<String>,
errors: BTreeMap<String, Box<ValidationErrors>>,
)
pub fn add_map_errors( &mut self, field: impl Into<String>, errors: BTreeMap<String, Box<ValidationErrors>>, )
Add map item errors
Sourcepub fn merge(&mut self, other: ValidationErrors)
pub fn merge(&mut self, other: ValidationErrors)
Merge another ValidationErrors into this one
Sourcepub fn merge_result<T>(
&mut self,
result: Result<T, ValidationErrors>,
) -> Option<T>
pub fn merge_result<T>( &mut self, result: Result<T, ValidationErrors>, ) -> Option<T>
Merge errors from a Result
Sourcepub fn to_flat_map(&self) -> BTreeMap<String, Vec<String>>
pub fn to_flat_map(&self) -> BTreeMap<String, Vec<String>>
Convert to a flat map format: “path” -> [“error1”, “error2”]
Useful for simpler error handling or compatibility with other formats.
Sourcepub fn field(&self, name: &str) -> Option<&FieldErrors>
pub fn field(&self, name: &str) -> Option<&FieldErrors>
Get errors for a specific field
Sourcepub fn has_field_error(&self, name: &str) -> bool
pub fn has_field_error(&self, name: &str) -> bool
Check if a specific field has errors
Sourcepub fn field_count(&self) -> usize
pub fn field_count(&self) -> usize
Get the number of fields with errors
Sourcepub fn field_errors(&self) -> impl Iterator<Item = (&String, &FieldErrors)>
pub fn field_errors(&self) -> impl Iterator<Item = (&String, &FieldErrors)>
Iterate over field errors
Trait Implementations§
Source§impl Clone for ValidationErrors
impl Clone for ValidationErrors
Source§fn clone(&self) -> ValidationErrors
fn clone(&self) -> ValidationErrors
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ValidationErrors
impl Debug for ValidationErrors
Source§impl Default for ValidationErrors
impl Default for ValidationErrors
Source§fn default() -> ValidationErrors
fn default() -> ValidationErrors
Returns the “default value” for a type. Read more
Source§impl Display for ValidationErrors
impl Display for ValidationErrors
Source§impl Error for ValidationErrors
impl Error for ValidationErrors
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl FromIterator<ValidationError> for ValidationErrors
impl FromIterator<ValidationError> for ValidationErrors
Source§fn from_iter<I: IntoIterator<Item = ValidationError>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = ValidationError>>(iter: I) -> Self
Creates a value from an iterator. Read more
Auto Trait Implementations§
impl Freeze for ValidationErrors
impl RefUnwindSafe for ValidationErrors
impl Send for ValidationErrors
impl Sync for ValidationErrors
impl Unpin for ValidationErrors
impl UnwindSafe for ValidationErrors
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