Closed gengteng closed 9 months ago
Just updated axum to 0.71 and everything seems fine except for some errors I get when trying to compile.
Apparently as soon as I use code like this:
/// Create a new news item for a given project.
///
async fn post_news(
State(bs): State<Arc<BackendState>>,
ExtractDeviceId(device_id): ExtractDeviceId,
Valid(Json(dto)): Valid<Json<NewsNew>>,
) -> Result<impl IntoResponse, ApiError> {
let (_, _account) = verify_device_and_account(&bs, device_id)?;
let project = crate::projects::services::find_project_by_id(&bs, dto.project_id)?;
let news = super::services::create_news_with_project(&bs, &project, &dto)?;
Ok(Json(news))
}
with the following errors:
error[E0277]: the trait bound `fn(axum::extract::State<std::sync::Arc<backend_state::BackendState>>, helpers::ExtractDeviceId, axum_valid::Valid<axum::Json<news::models::NewsNew>>) -> impl futures::Future<Output = std::result::Result<impl axum::response::IntoResponse, errors::ApiError>> {news::routes::post_news}: axum::handler::Handler<_, std::sync::Arc<backend_state::BackendState>>` is not satisfied
--> src/news/routes.rs:22:59
|
22 | .route("/v1/news", get(get_news_for_project).post(post_news))
| ---- ^^^^^^^^^ the trait `axum::handler::Handler<_, std::sync::Arc<backend_state::BackendState>>` is not implemented for fn item `fn(axum::extract::State<std::sync::Arc<backend_state::BackendState>>, helpers::ExtractDeviceId, axum_valid::Valid<axum::Json<news::models::NewsNew>>) -> impl futures::Future<Output = std::result::Result<impl axum::response::IntoResponse, errors::ApiError>> {news::routes::post_news}`
| |
| required by a bound introduced by this call
|
help: trait impls with same name found
--> /Users/bbense/.cargo/registry/src/index.crates.io-6f17d22bba15001f/axum-0.6.20/src/handler/mod.rs:198:1
|
198 | impl<F, Fut, Res, S, B> Handler<((),), S, B> for F
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
257 | all_the_tuples!(impl_handler);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
265 | impl<T, S, B> Handler<private::IntoResponseHandler, S, B> for T
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: perhaps two different versions of crate `axum` are being used?
= help: the following other types implement trait `axum::handler::Handler<T, S>`:
<axum::handler::Layered<L, H, T, S> as axum::handler::Handler<T, S>>
<axum::routing::MethodRouter<S> as axum::handler::Handler<(), S>>
note: required by a bound in `axum::routing::MethodRouter::<S>::post`
--> /Users/bbense/.cargo/registry/src/index.crates.io-6f17d22bba15001f/axum-0.7.1/src/routing/method_routing.rs:590:5
|
590 | chained_handler_fn!(post, POST);
| ^^^^^^^^^^^^^^^^^^^^----^^^^^^^
| | |
| | required by a bound in this associated function
| required by this bound in `MethodRouter::<S>::post`
= note: this error originates in the macro `impl_handler` which comes from the expansion of the macro `chained_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
Apparently, something is not quite right with the return type that axum expects now.
@bastibense
Try 0.12.0-alpha. If you encounter any issues or have specific questions, feel free to let me know, thx.
@bastibense
Try 0.12.0-alpha. If you encounter any issues or have specific questions, feel free to let me know, thx.
Just tried 0.12.0-alpha and it seems to compile just fine now. Will report back if I see any other bugs or side effects.
Thanks for the quick response! 👍
Awesome 🥳
Yaml
fromaxum-serde
MsgPack
andMsgPackRaw
fromaxum-serde
murar8/axum_typed_multipart#59