pub struct Errors { /* private fields */ }Expand description
Ordered collection of validation errors for a model instance.
Implementations§
Source§impl Errors
impl Errors
Sourcepub fn add(
&mut self,
attribute: &str,
error_type: ErrorType,
message: impl Into<String>,
) -> Error
pub fn add( &mut self, attribute: &str, error_type: ErrorType, message: impl Into<String>, ) -> Error
Adds an error without structured details.
Sourcepub fn add_message(
&mut self,
attribute: &str,
message: impl Into<String>,
) -> Error
pub fn add_message( &mut self, attribute: &str, message: impl Into<String>, ) -> Error
Adds an invalid error with a plain string message.
Sourcepub fn add_with_details(
&mut self,
attribute: &str,
error_type: ErrorType,
message: impl Into<String>,
details: HashMap<String, Value>,
) -> Error
pub fn add_with_details( &mut self, attribute: &str, error_type: ErrorType, message: impl Into<String>, details: HashMap<String, Value>, ) -> Error
Adds an error with structured details.
Sourcepub fn delete(&mut self, attribute: &str) -> Vec<String>
pub fn delete(&mut self, attribute: &str) -> Vec<String>
Removes every error associated with the given attribute and returns their messages.
Sourcepub fn on(&self, attribute: &str) -> Vec<&Error>
pub fn on(&self, attribute: &str) -> Vec<&Error>
Returns every error attached to the given attribute in insertion order.
Sourcepub fn added(
&self,
attribute: &str,
error_type: &ErrorType,
details: Option<&HashMap<String, Value>>,
) -> bool
pub fn added( &self, attribute: &str, error_type: &ErrorType, details: Option<&HashMap<String, Value>>, ) -> bool
Returns true when an error matching the provided conditions exists.
Sourcepub fn of_kind(&self, attribute: &str, error_type: &ErrorType) -> bool
pub fn of_kind(&self, attribute: &str, error_type: &ErrorType) -> bool
Returns true when an attribute has at least one error of the given kind.
Sourcepub fn full_messages(&self) -> Vec<String>
pub fn full_messages(&self) -> Vec<String>
Returns every error formatted as a human-readable full message.
Sourcepub fn full_messages_for(&self, attribute: &str) -> Vec<String>
pub fn full_messages_for(&self, attribute: &str) -> Vec<String>
Returns full messages for a single attribute in insertion order.
Sourcepub fn messages_for(&self, attribute: &str) -> Vec<String>
pub fn messages_for(&self, attribute: &str) -> Vec<String>
Returns the raw message strings for a single attribute in insertion order.
Sourcepub fn attributes(&self) -> Vec<&str>
pub fn attributes(&self) -> Vec<&str>
Returns each attribute name with at least one error, preserving first-seen order.
Sourcepub fn has_key(&self, attribute: &str) -> bool
pub fn has_key(&self, attribute: &str) -> bool
Returns true when the given attribute has at least one error.
Sourcepub fn as_json_with_full_messages(&self) -> Value
pub fn as_json_with_full_messages(&self) -> Value
Serializes grouped full messages as a JSON object.
Sourcepub fn group_by_attribute(&self) -> IndexMap<String, Vec<Error>>
pub fn group_by_attribute(&self) -> IndexMap<String, Vec<Error>>
Groups cloned errors by attribute in insertion order.
Sourcepub fn merge(&mut self, other: &Self)
pub fn merge(&mut self, other: &Self)
Appends cloned errors from another collection, ignoring self-merges.
Sourcepub fn where_attr(&self, attribute: &str) -> Vec<&Error>
pub fn where_attr(&self, attribute: &str) -> Vec<&Error>
Returns errors for a single attribute in insertion order.
Sourcepub fn where_type(&self, error_type: &ErrorType) -> Vec<&Error>
pub fn where_type(&self, error_type: &ErrorType) -> Vec<&Error>
Returns errors of a single type in insertion order.
Trait Implementations§
Source§impl<'a> IntoIterator for &'a Errors
impl<'a> IntoIterator for &'a Errors
impl StructuralPartialEq for Errors
Auto Trait Implementations§
impl Freeze for Errors
impl RefUnwindSafe for Errors
impl Send for Errors
impl Sync for Errors
impl Unpin for Errors
impl UnsafeUnpin for Errors
impl UnwindSafe for Errors
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more