2

I thought Handler should be implemented for an async function returning a StatusCode:

use axum::{
    headers,
    http::StatusCode,
    routing::{delete, get, post, put},
    Router,
};

pub fn create_routes() -> Router {
    Router::new().route("/webhook", post(webhook_handler()))
}

#[debug_handler]
async fn webhook_handler() -> StatusCode {
    StatusCode::OK
}
error[E0277]: the trait bound `impl futures::Future<Output = StatusCode>: Handler<_, _>` is not satisfied
   --> src/webhook.rs:16:39
    |
16  |     Router::new().route("/webhook", post(webhook_handler()))
    |                                     ---- ^^^^^^^^^^^^^^^^^ the trait `Handler<_, _>` is not implemented for `impl futures::Future<Output = StatusCode>`
    |                                     |
    |                                     required by a bound introduced by this call
    |
    = help: the trait `Handler<T, ReqBody>` is implemented for `Layered<S, T>`
note: required by a bound in `axum::routing::post`
   --> /home/andrew/.cargo/registry/src/github.com-1ecc6299db9ec823/axum-0.5.11/src/routing/method_routing.rs:400:1
    |
400 | top_level_handler_fn!(post, POST);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `axum::routing::post`
    = note: this error originates in the macro `top_level_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)

This seems nearly identical to an example provided in the documentation:

// `StatusCode` gives an empty response with that status code
async fn status() -> StatusCode {
    StatusCode::NOT_FOUND
}
kmdreko
  • 42,554
  • 6
  • 57
  • 106
The Mungler
  • 136
  • 1
  • 12

1 Answers1

4

The function itself needs to be passed as an argument to post, not a function call. Removed the parenthesis like so: .route("webhook", post(webhook_handler))

The Mungler
  • 136
  • 1
  • 12