[][src]Enum valid::ConstraintViolation

pub enum ConstraintViolation {
    Field(InvalidValue),
    Relation(InvalidRelation),
    State(InvalidState),
}

Represents a constraint violation found by some validation function.

The variants provide different details about a constraint violation. As described in the crate level documentation this crate considers 3 categories of business rules or constraints. Violations of constraints of the different categories might provide different details about the validation.

For example a field validation might provide the field name, the actual value and an example for the expected value. A constraint on the relation of a pair of fields might provide the names of the 2 fields. Stateful constraints may provide a list of parameters that might be useful to describe the reason of the constraint violation.

An implementation of a constraint should choose the most appropriate context for the kind of business rule it is implementing. Here is a table that shows the relation of the implemented context and the variant of the constraint violation type.

ContextConstraint ViolationConstruction Method
FieldNameFieldinvalid_value
invalid_optional_value
RelatedFieldsRelationinvalid_relation
State<S>Stateinvalid_state

The construction methods are a convenient way to construct ConstraintViolations.

ConstraintViolation can be serialized and deserialized using the serde crate. To use the serde support the optional crate feature serde1 must be enabled.

Variants

Violation of a constraint validated in the FieldName context

Relation(InvalidRelation)

Violation of a constraint validated in the RelatedField context

Violation of a constraint validated in the State context

Trait Implementations

impl Clone for ConstraintViolation[src]

impl Debug for ConstraintViolation[src]

impl<'de> Deserialize<'de> for ConstraintViolation[src]

impl Display for ConstraintViolation[src]

impl From<InvalidRelation> for ConstraintViolation[src]

impl From<InvalidState> for ConstraintViolation[src]

impl From<InvalidValue> for ConstraintViolation[src]

impl PartialEq<ConstraintViolation> for ConstraintViolation[src]

impl Serialize for ConstraintViolation[src]

impl StructuralPartialEq for ConstraintViolation[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.