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

Update axum from 0.6 to 0.7 #16

Closed
10 tasks done
gengteng opened this issue Nov 28, 2023 · 4 comments
Closed
10 tasks done

Update axum from 0.6 to 0.7 #16

gengteng opened this issue Nov 28, 2023 · 4 comments
Assignees

Comments

@gengteng
Copy link
Owner

gengteng commented Nov 28, 2023

@gengteng gengteng self-assigned this Nov 28, 2023
@bastibense
Copy link

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.

@gengteng
Copy link
Owner Author

gengteng commented Nov 28, 2023

@bastibense

Try 0.12.0-alpha. If you encounter any issues or have specific questions, feel free to let me know, thx.

@bastibense
Copy link

@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! 👍

@gengteng gengteng closed this as completed Dec 4, 2023
@bastibense
Copy link

Awesome 🥳

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