pub enum ConstraintViolation {
Field(InvalidValue),
Relation(InvalidRelation),
State(InvalidState),
}Expand description
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.
| Context | Constraint Violation | Construction Method |
|---|---|---|
FieldName | Field | invalid_valueinvalid_optional_value |
RelatedFields | Relation | invalid_relation |
State<S> | State | invalid_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§
Field(InvalidValue)
Violation of a constraint validated in the FieldName context
Relation(InvalidRelation)
Violation of a constraint validated in the RelatedField context
State(InvalidState)
Violation of a constraint validated in the State context
Trait Implementations§
Source§impl Clone for ConstraintViolation
impl Clone for ConstraintViolation
Source§fn clone(&self) -> ConstraintViolation
fn clone(&self) -> ConstraintViolation
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more