tokio-rs / axum

Ergonomic and modular web framework built with Tokio, Tower, and Hyper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handler not implemented for Or

Natureshadow opened this issue · comments

  • I have looked for existing issues (including closed) about this

Bug Report

Version

├── axum v0.7.4
│   ├── axum-core v0.4.3
├── axum-extra v0.9.2
│   ├── axum v0.7.4 (*)
│   ├── axum-core v0.4.3 (*)
│   ├── axum v0.7.4 (*)

Platform

Linux frifot 6.7.2-1-default #1 SMP PREEMPT_DYNAMIC Fri Jan 26 11:01:28 UTC 2024 (a52bf76) x86_64 x86_64 x86_64 GNU/Linux

Description

I have two functions with signatures:

pub(crate) async fn query_post_handler(
    state: State<AppState>,
    headers: HeaderMap,
    DirectOrForm(params): DirectOrForm<QueryParams>,
) -> axum::Result<Response<String>>

I am trying to use them in my router as:

        .route(
            "/",
            post(query::query_post_handler.or(update::update_post_handler)),
        )

However, this does not work as expected, with:

18  |             post(query::query_post_handler.or(update::update_post_handler)),
    |             ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Handler<_, _>` is not implemented for `axum_extra::handler::Or<fn(State<AppState>, HeaderMap, adapters::sparql::query::DirectOrForm<QueryParams>) -> impl Future<Output = Result<Response<String>, ErrorResponse>> {query_post_handler}, fn(State<AppState>, HeaderMap, adapters::sparql::update::DirectOrForm<UpdateParams>) -> impl Future<Output = Result<Response<String>, ErrorResponse>> {update_post_handler}, (State<AppState>, HeaderMap, adapters::sparql::query::DirectOrForm<QueryParams>), (State<AppState>, HeaderMap, adapters::sparql::update::DirectOrForm<UpdateParams>), _>`
    |             |
    |             required by a bound introduced by this call