pub struct Context<V>where
V: Invalidity,{ /* private fields */ }
Expand description
A collection of invalidities resulting from a validation
Collects invalidities that are detected while performing a validation.
Implementations
sourceimpl<V> Context<V>where
V: Invalidity,
impl<V> Context<V>where
V: Invalidity,
sourcepub fn invalidate(self, invalidity: impl Into<V>) -> Self
pub fn invalidate(self, invalidity: impl Into<V>) -> Self
Record a new invalidity within this context
sourcepub fn invalidate_if(
self,
is_invalid: impl Into<bool>,
invalidity: impl Into<V>
) -> Self
pub fn invalidate_if(
self,
is_invalid: impl Into<bool>,
invalidity: impl Into<V>
) -> Self
Conditionally record a new invalidity within this context
sourcepub fn merge_result(self, res: ValidationResult<V>) -> Self
pub fn merge_result(self, res: ValidationResult<V>) -> Self
Merge the results of another validation
Needed for collecting results from custom validation functions.
sourcepub fn merge_result_with<F, U>(self, res: ValidationResult<U>, map: F) -> Selfwhere
F: Fn(U) -> V,
U: Invalidity,
pub fn merge_result_with<F, U>(self, res: ValidationResult<U>, map: F) -> Selfwhere
F: Fn(U) -> V,
U: Invalidity,
Merge the mapped results of another validation
Needed for collecting results from custom validation functions.
sourcepub fn validate<U>(self, target: &impl Validate<Invalidity = U>) -> Selfwhere
U: Invalidity + Into<V>,
pub fn validate<U>(self, target: &impl Validate<Invalidity = U>) -> Selfwhere
U: Invalidity + Into<V>,
Validate the target and merge the result into this context
sourcepub fn validate_with<F, U>(
self,
target: &impl Validate<Invalidity = U>,
map: F
) -> Selfwhere
F: Fn(U) -> V,
U: Invalidity,
pub fn validate_with<F, U>(
self,
target: &impl Validate<Invalidity = U>,
map: F
) -> Selfwhere
F: Fn(U) -> V,
U: Invalidity,
Validate the target and merge the mapped result into this context
sourcepub fn into_result(self) -> ValidationResult<V>
pub fn into_result(self) -> ValidationResult<V>
Finish the validation
Finishes the current validation of this context with a result.
Errors
Returns Err
with the collected invalidities if one or more
validations failed.
Trait Implementations
sourceimpl<V: Clone> Clone for Context<V>where
V: Invalidity,
impl<V: Clone> Clone for Context<V>where
V: Invalidity,
sourceimpl<V: Debug> Debug for Context<V>where
V: Invalidity,
impl<V: Debug> Debug for Context<V>where
V: Invalidity,
sourceimpl<V: Default> Default for Context<V>where
V: Invalidity,
impl<V: Default> Default for Context<V>where
V: Invalidity,
sourceimpl<V> From<Context<V>> for ValidationResult<V>where
V: Invalidity,
impl<V> From<Context<V>> for ValidationResult<V>where
V: Invalidity,
sourceimpl<V> IntoIterator for Context<V>where
V: Invalidity,
impl<V> IntoIterator for Context<V>where
V: Invalidity,
Transform the validation context into an iterator that yields all the collected invalidities.
Auto Trait Implementations
impl<V> RefUnwindSafe for Context<V>where
V: RefUnwindSafe,
impl<V> Send for Context<V>where
V: Send,
impl<V> Sync for Context<V>where
V: Sync,
impl<V> Unpin for Context<V>where
V: Unpin,
impl<V> UnwindSafe for Context<V>where
V: UnwindSafe + RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T, V> IntoValidated<V> for Twhere
V: ValidatedFrom<T>,
impl<T, V> IntoValidated<V> for Twhere
V: ValidatedFrom<T>,
sourcefn into_validated(
self
) -> Result<Validated<V>, (V, Context<<V as Validate>::Invalidity>)>
fn into_validated(
self
) -> Result<Validated<V>, (V, Context<<V as Validate>::Invalidity>)>
self
into output value and validate the output Read more