pub trait Validate {
type Error;
// Required method
fn validate(&self) -> Result<(), Self::Error>;
}Expand description
A type that can validate itself.
Implement this trait to express the validity rules of a type. Use
Valid<T> to wrap validated values and carry the proof in the type
system.
§Example
use reliakit_validate::{Validate, ValidationError};
struct Score(u8);
impl Validate for Score {
type Error = ValidationError;
fn validate(&self) -> Result<(), Self::Error> {
if self.0 > 100 {
return Err(ValidationError::new("score must not exceed 100"));
}
Ok(())
}
}
assert!(Score(100).validate().is_ok());
assert!(Score(101).validate().is_err());Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".