Skip to main content

Errors

Struct Errors 

Source
pub struct Errors { /* private fields */ }
Expand description

Ordered collection of validation errors for a model instance.

Implementations§

Source§

impl Errors

Source

pub fn new() -> Self

Creates an empty error collection.

Source

pub fn add( &mut self, attribute: &str, error_type: ErrorType, message: impl Into<String>, ) -> Error

Adds an error without structured details.

Source

pub fn add_message( &mut self, attribute: &str, message: impl Into<String>, ) -> Error

Adds an invalid error with a plain string message.

Source

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.

Source

pub fn delete(&mut self, attribute: &str) -> Vec<String>

Removes every error associated with the given attribute and returns their messages.

Source

pub fn clear(&mut self)

Removes every error from the collection.

Source

pub fn on(&self, attribute: &str) -> Vec<&Error>

Returns every error attached to the given attribute in insertion order.

Source

pub fn is_empty(&self) -> bool

Returns true when no errors are present.

Source

pub fn count(&self) -> usize

Returns the number of stored errors.

Source

pub fn any(&self) -> bool

Returns true when at least one error is present.

Source

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.

Source

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.

Source

pub fn full_messages(&self) -> Vec<String>

Returns every error formatted as a human-readable full message.

Source

pub fn full_messages_for(&self, attribute: &str) -> Vec<String>

Returns full messages for a single attribute in insertion order.

Source

pub fn messages_for(&self, attribute: &str) -> Vec<String>

Returns the raw message strings for a single attribute in insertion order.

Source

pub fn attributes(&self) -> Vec<&str>

Returns each attribute name with at least one error, preserving first-seen order.

Source

pub fn details(&self) -> &[Error]

Returns the stored error details in insertion order.

Source

pub fn has_key(&self, attribute: &str) -> bool

Returns true when the given attribute has at least one error.

Source

pub fn to_hash(&self) -> HashMap<String, Vec<String>>

Groups messages by attribute.

Source

pub fn as_json(&self) -> Value

Serializes grouped messages as a JSON object.

Source

pub fn as_json_with_full_messages(&self) -> Value

Serializes grouped full messages as a JSON object.

Source

pub fn group_by_attribute(&self) -> IndexMap<String, Vec<Error>>

Groups cloned errors by attribute in insertion order.

Source

pub fn copy_from(&mut self, other: &Self)

Appends cloned errors from another collection.

Source

pub fn merge(&mut self, other: &Self)

Appends cloned errors from another collection, ignoring self-merges.

Source

pub fn where_attr(&self, attribute: &str) -> Vec<&Error>

Returns errors for a single attribute in insertion order.

Source

pub fn where_type(&self, error_type: &ErrorType) -> Vec<&Error>

Returns errors of a single type in insertion order.

Source

pub fn where_attr_type( &self, attribute: &str, error_type: &ErrorType, ) -> Vec<&Error>

Returns errors matching both an attribute and an error type in insertion order.

Trait Implementations§

Source§

impl Clone for Errors

Source§

fn clone(&self) -> Errors

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Errors

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Errors

Source§

fn default() -> Errors

Returns the “default value” for a type. Read more
Source§

impl Display for Errors

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> IntoIterator for &'a Errors

Source§

type Item = &'a Error

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Error>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Errors

Source§

fn eq(&self, other: &Errors) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Errors

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Errors

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToJson for T
where T: Serialize,

Source§

fn to_json(&self) -> Value

Converts self into JSON.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more