Skip to main content

Module validate

Module validate 

Source
Expand description

The Validate trait and its implementations for standard types.

Validation has two phases, mirroring Pydantic’s before/after split:

  1. Validate::prepare runs on the raw Value before deserialization. It is type driven: every type checks and, in lax mode, coerces its own slot of the input ("42" → 42 for integers, trimming for strings, …). Derived models walk their fields, report missing/extra keys and recurse with the location extended. Because all errors are collected here, one request reports every problem at once.
  2. Validate::validate runs on the typed value after deserialization: field constraints, after-validators, model validators.

Both phases push errors into a ValidationContext; neither panics.

Traits§

Validate
A type that takes part in validation.