samscott89 / serde_qs

Serde support for querystring-style strings
Apache License 2.0
193 stars 68 forks source link

`QsQuery` 's implementation is not compatible with `axum` 0.6.0 #75

Closed elertan closed 1 year ago

elertan commented 1 year ago

Trying to compile:

use std::net::SocketAddr;

use axum::Router;
use axum::routing::get;
use serde::Deserialize;
use serde_qs::axum::QsQuery;

#[tokio::main]
async fn main() {
    let app = Router::new()
        .route("/", get(root));

    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
    axum::Server::bind(&addr)
        .serve(app.into_make_service())
        .await
        .unwrap();
}

#[derive(Deserialize)]
struct MyQuery {
    sequence: Vec<i32>,
}

async fn root(QsQuery(qs): QsQuery<MyQuery>) -> &'static str {
    "Hello, World!"
}

results in the error:

cargo build
   Compiling num_cpus v1.14.0
   Compiling tokio v1.22.0
   Compiling tower v0.4.13
   Compiling hyper v0.14.23
   Compiling tower-http v0.3.5
   Compiling axum v0.5.17
   Compiling axum v0.6.1
   Compiling serde_qs v0.10.1
   Compiling axum-six-dot-o-qs-query-not-compatible-poc v0.1.0 (/Users/denniskievits/Projects/axum-six-dot-o-qs-query-not-compatible-poc)
error[E0277]: the trait bound `fn(QsQuery<MyQuery>) -> impl Future<Output = &'static str> {root}: Handler<_, _, _>` is not satisfied
   --> src/main.rs:11:25
    |
11  |         .route("/", get(root));
    |                     --- ^^^^ the trait `Handler<_, _, _>` is not implemented for fn item `fn(QsQuery<MyQuery>) -> impl Future<Output = &'static str> {root}`
    |                     |
    |                     required by a bound introduced by this call
    |
    = help: the trait `Handler<T, S, B2>` is implemented for `Layered<L, H, T, S, B, B2>`
note: required by a bound in `axum::routing::get`
   --> /Users/denniskievits/.cargo/registry/src/github.com-1ecc6299db9ec823/axum-0.6.1/src/routing/method_routing.rs:403:1
    |
403 | top_level_handler_fn!(get, GET);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `axum::routing::get`
    = note: this error originates in the macro `top_level_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
error: could not compile `axum-six-dot-o-qs-query-not-compatible-poc` due to previous error

I have a repo which showcases the issue at hand available at https://github.com/elertan/axum-six-dot-o-qs-query-not-compatible-poc

See https://github.com/tamasfe/aide/issues/22#issuecomment-1335010238 to see where the original error originates from.

elertan commented 1 year ago

https://github.com/samscott89/serde_qs/pull/73

Seems like this PR would fix the issue

samscott89 commented 1 year ago

Thanks @davidpdrsn for the help in #73. axum 0.6 is supported in 0.11