Skip to main content

Module typed_response

Module typed_response 

Source
Expand description

Typed response wrapper for compile-time return type enforcement.

Strict<E> wraps an endpoint to enforce that the handler returns the exact type declared in the API spec. Without Strict, handlers can return any impl IntoResponse regardless of the declared Res.

§Example

type API = (
    // Handler MUST return Json<Vec<User>> — compiler enforced
    Strict<GetEndpoint<UsersPath, Json<Vec<User>>>>,

    // Handler can return anything implementing IntoResponse
    GetEndpoint<TagsPath, TagsResponse>,
);

// This compiles — return type matches Res:
async fn list_users() -> Json<Vec<User>> { Json(vec![]) }

// This would NOT compile — String ≠ Json<Vec<User>>:
// async fn list_users() -> String { "nope".into() }

Structs§

Strict
An endpoint that enforces the handler’s return type matches Res.
StrictWithBody
Marker for strict handlers with a body extractor.

Traits§

HasErrType
Trait to extract the Err type from an endpoint.
HasResType
Trait to extract the Res type from an endpoint.
StrictEndpoint
Trait to extract binding info from a Strict endpoint.
StrictHandler
A handler that returns exactly type Res.

Functions§

bind_strict
Bind a handler to a Strict<E> endpoint.