Skip to main content

Module validation

Module validation 

Source
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§

ValidationException
Validation failure for one field.

Traits§

Validate
Validator implemented for DTOs. Called by body parsing; validate may also be invoked directly.

Functions§

combine_and
Requires every validator in validators to pass, returning the first failure.
combine_not
Requires at least one of validators to fail. Succeeds on empty input; fails when all pass.
combine_or
Requires at least one of validators to pass; combines their messages on failure.
is_after
Requires value to be strictly after bound.
is_before
Requires value to be strictly before bound.
is_between
Requires n inside [start, end] (inclusive) or (start, end) (exclusive).
is_email
Requires value to match a basic local@domain.tld email shape.
is_greater
Requires n above bound (inclusive when or_equals is true).
is_in
Requires value to equal one of allowed.
is_length
Requires a string’s byte length to be within [min, max].
is_lesser
Requires n below bound (inclusive when or_equals is true).
is_match
Requires value to match the regex pattern. An invalid pattern is itself an error.
is_negative
Requires n to 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 n outside [start, end]; inclusive widens the rejected interval to include the bounds.
is_positive
Requires n to be strictly positive.
is_size
Requires a length/count len to be within [min, max].
is_url
Requires value to parse as a URL with a host.
is_uuid
Requires value to parse as a UUID.
validate
Runs Validate::validate on target, returning the first failure.