Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different Extractor Order May Cause an Error #2317

Closed
1 task done
dupeiran001 opened this issue Nov 15, 2023 · 1 comment
Closed
1 task done

Different Extractor Order May Cause an Error #2317

dupeiran001 opened this issue Nov 15, 2023 · 1 comment

Comments

@dupeiran001
Copy link

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

Bug Report

Version

├── axum v0.6.20
│ ├── axum-core v0.3.4
│ ├── axum v0.6.20 ()
│ │ │ ├── axum v0.6.20 (
)

Platform

Linux LAPTOP-0F8O2SNI 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Description

I have a State<_> extractor and a Json<_> extractor, and it cause an error when I place State<_> after Json<_>, it works well when these two are reversed.

I tried this code:

this works:

pub async fn demo_server(
    State(app): State<App>,
    Json(vo): Json<Vo>,
) -> String {
    todo!()
}

and this not:

pub async fn demo_server(
    Json(vo): Json<Vo>,
    State(app): State<App>,
) -> String {
    todo!()
}

App is my custom state, and Vo is an input parameter from request, which has implemented Deserialize

in the wrong code snippt, it has the following error message when add the function to router:

error[E0277]: the trait bound `fn(axum::Json<vo::pdf_convert::PdfConvertVo>, axum::extract::State<ryplat::app::App>) -> impl futures_util::Future<Output = ryplat::api::common::ResultDTO<std::string::String>> {service::file_convert::pdf_convert::pdf_to_image}: axum::handler::Handler<_, _, _>` is not satisfied
   --> src/main.rs:18:48
    |
18  |         .route("/a/convert/pdf/to/image", post(pdf_to_image))
    |                                           ---- ^^^^^^^^^^^^ the trait `axum::handler::Handler<_, _, _>` is not implemented for fn item `fn(axum::Json<vo::pdf_convert::PdfConvertVo>, axum::extract::State<ryplat::app::App>) -> impl futures_util::Future<Output = ryplat::api::common::ResultDTO<std::string::String>> {service::file_convert::pdf_convert::pdf_to_image}`
    |                                           |
    |                                           required by a bound introduced by this call
    |
    = help: the following other types implement trait `axum::handler::Handler<T, S, B>`:
              <axum::handler::Layered<L, H, T, S, B, B2> as axum::handler::Handler<T, S, B2>>
              <axum::routing::MethodRouter<S, B> as axum::handler::Handler<(), S, B>>
note: required by a bound in `axum::routing::post`
   --> /home/dpr/.cargo/registry/src/crates.obei.com.cn-8e030f22a0aa026e/axum-0.6.20/src/routing/method_routing.rs:407:1
    |
407 | top_level_handler_fn!(post, POST);
    | ^^^^^^^^^^^^^^^^^^^^^^----^^^^^^^
    | |                     |
    | |                     required by a bound in this function
    | required by this bound in `post`
    = note: this error originates in the macro `top_level_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)

@jplatte
Copy link
Member

jplatte commented Nov 15, 2023

@jplatte jplatte closed this as not planned Won't fix, can't repro, duplicate, stale Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants