pub struct Valid<T>(/* private fields */);Expand description
A value that has been successfully validated.
Valid<T> is a zero-cost wrapper that carries proof of validation in the
type system. Construction requires the value to pass Validate::validate.
Once inside Valid<T>, the value is considered correct by the validation
rules of T.
§Examples
use reliakit_validate::{Validate, Valid, ValidationError};
struct Age(u8);
impl Validate for Age {
type Error = ValidationError;
fn validate(&self) -> Result<(), Self::Error> {
if self.0 > 120 {
return Err(ValidationError::new("age must not exceed 120"));
}
Ok(())
}
}
let age = Valid::new(Age(25)).unwrap();
assert_eq!(age.0, 25);Implementations§
Trait Implementations§
Source§impl<T: Ord> Ord for Valid<T>
impl<T: Ord> Ord for Valid<T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialOrd> PartialOrd for Valid<T>
impl<T: PartialOrd> PartialOrd for Valid<T>
impl<T: Eq> Eq for Valid<T>
impl<T> StructuralPartialEq for Valid<T>
Auto Trait Implementations§
impl<T> Freeze for Valid<T>where
T: Freeze,
impl<T> RefUnwindSafe for Valid<T>where
T: RefUnwindSafe,
impl<T> Send for Valid<T>where
T: Send,
impl<T> Sync for Valid<T>where
T: Sync,
impl<T> Unpin for Valid<T>where
T: Unpin,
impl<T> UnsafeUnpin for Valid<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Valid<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more