[−][src]Struct valid::ValidationError
The error type returned if the validation finds any constraint violation.
It holds a list of constraint violations and an optional message. The message is meant to describe the context in which the validation has been performed. It is helpful when validating a struct that represents an input form or a REST command. In such cases the message would be something like "validating registration form" or "invalid post entry command".
The Display
and Error
traits are implemented to be compatible with most
error management concepts. It can be converted into failure::Error
using
From
or Into
conversion traits.
It can be serialized and deserialized using the serde
crate. To enable
serde
support the optional crate feature serde1
must be enabled.
Fields
message: Option<Cow<'static, str>>
Message that describes the context in which the validation has been executed
violations: Vec<ConstraintViolation>
A list of constraint violations found during validation
Methods
impl ValidationError
[src]
pub fn merge(self, other: ValidationError) -> Self
[src]
Merges this validation error with another validation error and returns a new validation error that contains all constraint violations from both errors merged into one list.
If both of the validation errors contain a message than the messages
are concatenated separated by the string ' / '
. If only one of the
two errors contain a message than this message becomes the message of
the resulting error.
Examples
use valid::{ValidationError, invalid_value}; let validation_error1 = ValidationError { message: Some("validating a user's age".into()), violations: vec![invalid_value("invalid-bound-min", "age", 12, 13)], }; let validation_error2 = ValidationError { message: Some("validating a user registration command".into()), violations: vec![invalid_value("invalid-length-min", "username", 3, 4)], }; let merged_error = validation_error2.merge(validation_error1); assert_eq!( merged_error, ValidationError { message: Some( "validating a user registration command / validating a user's age".into() ), violations: vec![ invalid_value("invalid-length-min", "username", 3, 4), invalid_value("invalid-bound-min", "age", 12, 13), ] } );
Trait Implementations
impl Clone for ValidationError
[src]
fn clone(&self) -> ValidationError
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl PartialEq<ValidationError> for ValidationError
[src]
fn eq(&self, other: &ValidationError) -> bool
[src]
fn ne(&self, other: &ValidationError) -> bool
[src]
impl Display for ValidationError
[src]
impl Debug for ValidationError
[src]
impl Error for ValidationError
[src]
fn description(&self) -> &str
1.0.0[src]
fn cause(&self) -> Option<&dyn Error>
1.0.0[src]
fn source(&self) -> Option<&(dyn Error + 'static)>
1.30.0[src]
impl Serialize for ValidationError
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<'de> Deserialize<'de> for ValidationError
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
Auto Trait Implementations
impl Unpin for ValidationError
impl Sync for ValidationError
impl Send for ValidationError
impl UnwindSafe for ValidationError
impl RefUnwindSafe for ValidationError
Blanket Implementations
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,