Skip to main content

Module validation

Module validation 

Source
Expand description

Validated<T> – type-branded, deserialized-and-validated request payload.

Unlike the #[Body] dto: T shorthand (which validates silently), Validated<T> makes the validation contract visible at the type level. Functions that only accept pre-validated inputs declare Validated<T> in their signature; the type system enforces the invariant across the call stack.

§Usage

async fn create_user(ctx: RequestContext) -> Result<Json<User>, HttpException> {
    let dto = Validated::<CreateUserDto>::from_body(&ctx)?;
    service.create(dto.into_inner()).await
}

§RFC 7807 Error Shape

Deserialize failure -> 400 Bad Request (bad-request problem type) Constraint violation -> 422 Unprocessable Entity (validation problem type) with per-field errors array

Structs§

Validated
A payload T that has been deserialized and validated.