pub struct ValidationErrors { /* private fields */ }Expand description
A collection of validation errors from validating a struct.
This type aggregates all validation errors found during validation,
allowing users to see all problems at once rather than fixing them
one at a time. It implements both JSON serialization (for API responses)
and human-readable Display (for CLI/logging output).
§Example
use rusdantic_core::{ValidationErrors, ValidationError, PathSegment};
let mut errors = ValidationErrors::new();
assert!(errors.is_empty());
errors.add(ValidationError {
path: vec![PathSegment::Field("email".to_string())],
code: "email".to_string(),
message: "invalid email format".to_string(),
params: Default::default(),
});
assert_eq!(errors.len(), 1);
assert!(!errors.is_empty());Implementations§
Source§impl ValidationErrors
impl ValidationErrors
Sourcepub fn add(&mut self, error: ValidationError)
pub fn add(&mut self, error: ValidationError)
Add a single validation error to the collection.
Sourcepub fn merge(&mut self, other: ValidationErrors)
pub fn merge(&mut self, other: ValidationErrors)
Merge another ValidationErrors into this one.
All errors from other are moved into this collection.
Sourcepub fn errors(&self) -> &[ValidationError]
pub fn errors(&self) -> &[ValidationError]
Get a reference to the collected errors.
Sourcepub fn into_errors(self) -> Vec<ValidationError>
pub fn into_errors(self) -> Vec<ValidationError>
Consume self and return the inner vector of errors.
Sourcepub fn field_errors(&self, field_name: &str) -> Vec<&ValidationError>
pub fn field_errors(&self, field_name: &str) -> Vec<&ValidationError>
Get errors for a specific field path (first segment only).
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§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<'a> IntoIterator for &'a ValidationErrors
impl<'a> IntoIterator for &'a ValidationErrors
Source§impl IntoIterator for ValidationErrors
impl IntoIterator for ValidationErrors
Auto Trait Implementations§
impl Freeze for ValidationErrors
impl RefUnwindSafe for ValidationErrors
impl Send for ValidationErrors
impl Sync for ValidationErrors
impl Unpin for ValidationErrors
impl UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Dump for Twhere
T: Serialize,
impl<T> Dump for Twhere
T: Serialize,
Source§fn dump_with(&self, options: &DumpOptions) -> Result<Value, Error>
fn dump_with(&self, options: &DumpOptions) -> Result<Value, Error>
Serialize to a
serde_json::Value with custom options.Source§fn dump_json_with(&self, options: &DumpOptions) -> Result<String, Error>
fn dump_json_with(&self, options: &DumpOptions) -> Result<String, Error>
Serialize to a JSON string with custom options.