[−][src]Struct valid::Validation
State of an ongoing validation.
It provides combinator methods like and
and and_then
to combine
validation steps to complex validations and accumulates all constraint
violations found by the executed validations.
The result of a validation can be obtained by calling the result
method.
see the crate level documentation for details and examples on how to use the methods provided by this struct.
Implementations
impl<C, T> Validation<C, T>
[src]
pub fn success(valid: T) -> Self
[src]
Constructs a Validation
for a successful validation step.
This method is provided to enable users of this crate to implement custom validation functions.
pub fn failure(
constraint_violations: impl IntoIterator<Item = ConstraintViolation>
) -> Self
[src]
constraint_violations: impl IntoIterator<Item = ConstraintViolation>
) -> Self
Constructs a Validation
for a failed validation step.
This method is provided to enable users of this crate to implement custom validation functions.
pub fn result(self) -> ValidationResult<C, T>
[src]
Finishes a validation and returns the result of the validation.
A validation may comprise multiple validation steps that are combined
using the combinator methods of this struct. After all steps are
executed this method can be called to get the ValidationResult
pub fn with_message(
self,
message: impl Into<Cow<'static, str>>
) -> ValidationResult<C, T>
[src]
self,
message: impl Into<Cow<'static, str>>
) -> ValidationResult<C, T>
Finishes a validation providing a message and returns the result.
A validation may comprise multiple validation steps that are combined
using the combinator methods of this struct. After all steps are
executed this method can be called to get the ValidationResult
In case of an error the ValidationError
will contain the given
message. It is meant to describe the context in which the validation has
been executed. E.g when validating a struct that represents an input
form the message would be something like "validating registration form"
or when validating a struct that represents a REST command the message
would be something like "invalid post entry command".
pub fn combine<U>(self, value: U) -> Validation<C, (U, T)>
[src]
Combines a value that needs no further validation with the validation result.
This method may be especially useful in combination with the
and_then
combinator method. See the crate level documentation for
an example.
pub fn map<D, U>(self, convert: impl Fn(T) -> U) -> Validation<D, U>
[src]
Maps the validated values into another type.
This method is used for complex validations that validate multiple fields of a struct and the result should be mapped back into this struct. See the crate level documentation for an example.
pub fn and<D, U>(self, other: Validation<D, U>) -> Validation<D, (T, U)>
[src]
Combines this validation with another validation unconditionally.
The other validation is executed regardless whether this validation has been successful or not.
The resulting validation is only successful if itself was successful and the other validation is also successful. Any constraint violations found either by this validation or the other validation are accumulated.
See the crate level documentation for an example.
pub fn and_then<D, U>(
self,
next: impl FnOnce(T) -> Validation<D, U>
) -> Validation<D, U>
[src]
self,
next: impl FnOnce(T) -> Validation<D, U>
) -> Validation<D, U>
Combines this validation with another validation conditionally.
The other validation is only executed if this validation has been successful. It has access to the values that have been validated so far.
Those values are provided in a tuple as an argument to the given
closure. If there is one value that has been validated so far the
argument T
to the closure is simple the type of the value. In case of
two values T
is a tuple of type (A, B)
, in case of 3 values the type
of T
is a tuple of a tuple and the 3rd value like ((A, B), C)
and
so on.
Values that are given as argument to the closure but not used for the
other validation are not part of the final result of the validation.
To add unused values to the result of the validation we can use the
combine
method.
See the crate level documentation for an example.
Trait Implementations
impl<C, T> Debug for Validation<C, T> where
C: Debug,
T: Debug,
[src]
C: Debug,
T: Debug,
impl<C: PartialEq, T: PartialEq> PartialEq<Validation<C, T>> for Validation<C, T>
[src]
fn eq(&self, other: &Validation<C, T>) -> bool
[src]
fn ne(&self, other: &Validation<C, T>) -> bool
[src]
impl<C, T> StructuralPartialEq for Validation<C, T>
[src]
Auto Trait Implementations
impl<C, T> RefUnwindSafe for Validation<C, T> where
C: RefUnwindSafe,
T: RefUnwindSafe,
C: RefUnwindSafe,
T: RefUnwindSafe,
impl<C, T> Send for Validation<C, T> where
C: Send,
T: Send,
C: Send,
T: Send,
impl<C, T> Sync for Validation<C, T> where
C: Sync,
T: Sync,
C: Sync,
T: Sync,
impl<C, T> Unpin for Validation<C, T> where
C: Unpin,
T: Unpin,
C: Unpin,
T: Unpin,
impl<C, T> UnwindSafe for Validation<C, T> where
C: UnwindSafe,
T: UnwindSafe,
C: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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>,