Skip to main content

ResponseProduces

Trait ResponseProduces 

Source
pub trait ResponseProduces<T> { }
Expand description

Marker trait for compile-time response type verification.

This trait is used by the route macros to verify at compile time that a handler’s return type can produce the declared OpenAPI response schema.

§How It Works

When you declare #[get("/users", response(200, User))], the macro generates a compile-time assertion that checks if the handler’s return type implements ResponseProduces<User>.

The implementation uses a simple blanket implementation: any type T that implements IntoResponse trivially produces itself as a schema.

For wrapper types like Json<T>, they implement ResponseProduces<T> to indicate they produce the inner type’s schema.

§Example

// This compiles because User produces User schema
#[get("/user/{id}", response(200, User))]
async fn get_user(Path(id): Path<i64>) -> User {
    User { id, name: "Alice".into() }
}

// This also compiles because Json<User> produces User schema
#[get("/user/{id}", response(200, User))]
async fn get_user(Path(id): Path<i64>) -> Json<User> {
    Json(User { id, name: "Alice".into() })
}

Implementors§

Source§

impl<T> ResponseProduces<T> for T

Source§

impl<T: Serialize + 'static> ResponseProduces<T> for Json<T>