Different combination of extractors in a method router/handler causes errors (0.6.0-rc.2) #1508
-
Hi, I have a method router in 0.6.0-rc.2: pub async fn set_hero(
user: AuthenticatedUser,
Path(config_id): Path<ConfigId>,
Json(request): Json<SetHeroRequest>,
State(mut db): State<Db>,
) -> Result<impl IntoResponse, ApiError> {
Ok(Json(Empty {}))
} Set up like this: let app = Router::with_state(state.clone())
.route("/api/auth/start/", get(api::oauth::auth_start))
.route("/api/auth/complete/", get(api::oauth::auth_complete))
.route(
"/api/counters/:config_id/set-hero/",
post(api::config::set_hero), // <-- This is the fn in question
)
.route("/api/counters/strengths/", get(api::config::strengths))
// Few more similar routes, then a layer for `AuthenticatedUser` to access:
.layer(Extension(state)); Strangely, if I comment a certain set of combination of extractors, it builds, otherwise when there are these 4 as is it fails to build: error[E0277]: the trait bound `fn(AuthenticatedUser, axum::extract::Path<ConfigId>, axum::Json<SetHeroRequest>, State<Db>) -> impl Future<Output = Result<impl IntoResponse, ApiError>> {set_hero}: Handler<_, _, _>` is not satisfied
--> server\src\main.rs:77:18
|
77 | post(api::config::set_hero),
| ---- ^^^^^^^^^^^^^^^^^^^^^ the trait `Handler<_, _, _>` is not implemented for `fn(AuthenticatedUser, axum::extract::Path<ConfigId>, axum::Json<SetHeroRequest>, State<Db>) -> impl Future<Output = Result<impl IntoResponse, ApiError>> {set_hero}`
| |
| required by a bound introduced by this call
|
= help: the trait `Handler<T, S, B>` is implemented for `axum::handler::Layered<L, H, T, S, B>`
note: required by a bound in `post`
--> .cargo\registry\src\github.com-1ecc6299db9ec823\axum-0.6.0-rc.2\src\routing\method_routing.rs:404:1
|
404 | top_level_handler_fn!(post, POST);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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) The combinations that work seem strange to me. Any two of these combined compile fine. 3 work together only sometimes, i.e. I'm having trouble finding clues to what the error means and how I can fix the problem, as I can't pinpoint what extractor might be causing the problem, or if I'm doing something silly otherwise.
Let me know if you need more code or a full reproduction. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Try https://docs.rs/axum/0.6.0-rc.2/axum/attr.debug_handler.html But it most likely that you need to make |
Beta Was this translation helpful? Give feedback.
Try https://docs.rs/axum/0.6.0-rc.2/axum/attr.debug_handler.html
But it most likely that you need to make
Json
the last argument. See https://docs.rs/axum/0.6.0-rc.2/axum/extract/index.html#the-order-of-extractors