pub struct SchemaErrors(/* private fields */);Expand description
A non-empty collection of schema validation errors.
SchemaErrors wraps a NonEmptyVec<SchemaError> to guarantee that at least
one error is present. This is essential for use with Validation<T, SchemaErrors>
since a failure must have at least one error.
§Combining Errors
SchemaErrors implements Semigroup, allowing errors from multiple
validations to be combined:
use postmortem::{JsonPath, SchemaError, SchemaErrors};
use stillwater::prelude::*;
let errors1 = SchemaErrors::single(
SchemaError::new(JsonPath::root().push_field("name"), "required")
);
let errors2 = SchemaErrors::single(
SchemaError::new(JsonPath::root().push_field("email"), "invalid format")
);
let combined = errors1.combine(errors2);
assert_eq!(combined.len(), 2);Implementations§
Source§impl SchemaErrors
impl SchemaErrors
Sourcepub fn single(error: SchemaError) -> Self
pub fn single(error: SchemaError) -> Self
Creates a SchemaErrors containing a single error.
Sourcepub fn from_non_empty(errors: NonEmptyVec<SchemaError>) -> Self
pub fn from_non_empty(errors: NonEmptyVec<SchemaError>) -> Self
Creates a SchemaErrors from a NonEmptyVec of errors.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns false since this collection is guaranteed non-empty.
This method exists for API consistency but always returns false.
Sourcepub fn iter(&self) -> impl Iterator<Item = &SchemaError>
pub fn iter(&self) -> impl Iterator<Item = &SchemaError>
Returns an iterator over the contained errors.
Sourcepub fn at_path(&self, path: &JsonPath) -> Vec<&SchemaError>
pub fn at_path(&self, path: &JsonPath) -> Vec<&SchemaError>
Returns all errors at the specified path.
Sourcepub fn with_code(&self, code: &str) -> Vec<&SchemaError>
pub fn with_code(&self, code: &str) -> Vec<&SchemaError>
Returns all errors with the specified error code.
Sourcepub fn first(&self) -> &SchemaError
pub fn first(&self) -> &SchemaError
Returns the first error in the collection.
Sourcepub fn into_vec(self) -> Vec<SchemaError>
pub fn into_vec(self) -> Vec<SchemaError>
Converts this collection into a Vec<SchemaError>.
Sourcepub fn as_non_empty_vec(&self) -> &NonEmptyVec<SchemaError>
pub fn as_non_empty_vec(&self) -> &NonEmptyVec<SchemaError>
Returns a reference to the underlying NonEmptyVec.
Sourcepub fn from_vec(errors: Vec<SchemaError>) -> Self
pub fn from_vec(errors: Vec<SchemaError>) -> Self
Creates a SchemaErrors from a Vec<SchemaError>.
Returns the SchemaErrors if the vec is non-empty, or panics if empty.
Use this when you’re certain the vec contains at least one error.
§Panics
Panics if the provided vec is empty.
Trait Implementations§
Source§impl Clone for SchemaErrors
impl Clone for SchemaErrors
Source§fn clone(&self) -> SchemaErrors
fn clone(&self) -> SchemaErrors
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more