Expand description
DTO validation.
Validate is implemented for request DTOs to check their fields, and
ValidationException describes the first failure. The is_* helpers check
single constraints (UUID, email, pattern, ranges, dates, and more) and the
combine_* helpers compose checks with and/or/not semantics.
ⓘ
impl Validate for CreateUser {
fn validate(&self) -> Result<(), ValidationException> {
is_email("email", &self.email, None)?;
is_length("name", &self.name, 1, 100, None)?;
Ok(())
}
}
let dto: CreateUser = ctx.body::<CreateUser>()?;Structs§
- Validation
Exception - Validation failure for one field.
Traits§
- Validate
- Validator implemented for DTOs. Called by body parsing;
validatemay also be invoked directly.
Functions§
- combine_
and - Requires every validator in
validatorsto pass, returning the first failure. - combine_
not - Requires at least one of
validatorsto fail. Succeeds on empty input; fails when all pass. - combine_
or - Requires at least one of
validatorsto pass; combines their messages on failure. - is_
after - Requires
valueto be strictly afterbound. - is_
before - Requires
valueto be strictly beforebound. - is_
between - Requires
ninside[start, end](inclusive) or(start, end)(exclusive). - is_
email - Requires
valueto match a basiclocal@domain.tldemail shape. - is_
greater - Requires
nabovebound(inclusive whenor_equalsis true). - is_in
- Requires
valueto equal one ofallowed. - is_
length - Requires a string’s byte length to be within
[min, max]. - is_
lesser - Requires
nbelowbound(inclusive whenor_equalsis true). - is_
match - Requires
valueto match the regexpattern. An invalid pattern is itself an error. - is_
negative - Requires
nto be strictly negative. - is_
not_ blank - Requires a string to contain a non-whitespace character.
- is_
not_ empty - Requires a JSON value to be non-empty (non-null, non-empty string/array/object).
- is_
outside - Requires
noutside[start, end];inclusivewidens the rejected interval to include the bounds. - is_
positive - Requires
nto be strictly positive. - is_size
- Requires a length/count
lento be within[min, max]. - is_url
- Requires
valueto parse as a URL with a host. - is_uuid
- Requires
valueto parse as a UUID. - validate
- Runs
Validate::validateontarget, returning the first failure.