#[handler]Expand description
Validates a handler function at its definition site.
Checks that:
- The function is
async - All arguments (except the last) implement
FromRequestParts - The last argument implements either
FromRequestPartsorFromRequest - The return type implements
IntoResponse
The function is emitted unchanged. It already works with bind and
the blanket Handler<Args> impls. This macro exists purely for early,
readable compile errors instead of cryptic trait-resolution failures at
the Server::new call site.
§Example
ⓘ
#[handler]
async fn get_user(path: Path<UserByIdPath>, state: State<AppState>) -> Json<User> {
// ...
}§Compile errors
ⓘ
#[handler]
fn not_async() -> String { "hello".to_string() }
// error: handler functions must be async
#[handler]
async fn bad_return() -> NotAResponse { NotAResponse }
// error: `NotAResponse` does not implement `IntoResponse`