pub trait Validate: Sized {
// Required method
fn validate(&mut self) -> Result<(), ValidationErrors>;
}Expand description
Normalise a value in place, then check it.
Derived with #[derive(Validate)]. Implement by hand only when the rules cannot be
spelled as attributes.
&mut self is not an accident: trim and lowercase rewrite the value, and a
validator that could only say no would leave every caller to do the normalising
itself — which is the boilerplate this exists to delete.
Required Methods§
Sourcefn validate(&mut self) -> Result<(), ValidationErrors>
fn validate(&mut self) -> Result<(), ValidationErrors>
Rewrite this value into its normalised form and return every rule it breaks.
Errors accumulate: a body with three bad fields reports all three, because making a user fix one mistake per round-trip is its own kind of bug.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".