audunhalland / entrait

Loosely coupled Rust application design made easy
83 stars 1 forks source link

Axum example doesn't compile #19

Closed TheDan64 closed 1 year ago

TheDan64 commented 1 year ago

Cloned main and tried to compile the axum example but was met with (r1.65.0):

error[E0433]: failed to resolve: could not find `__async_trait` in `entrait`
  --> examples/axum/src/main.rs:14:36
   |
14 |     #[entrait(pub GetFoo, no_deps, box_future, mock_api=GetFooMock)]
   |                                    ^^^^^^^^^^ could not find `__async_trait` in `entrait`

error[E0706]: functions in traits cannot be declared `async`
  --> examples/axum/src/main.rs:14:5
   |
14 |     #[entrait(pub GetFoo, no_deps, box_future, mock_api=GetFooMock)]
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15 |     async fn get_foo() -> Foo {
   |     ----- `async` because of this
   |
   = note: `async` trait functions are not currently supported
   = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
   = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
   = note: this error originates in the attribute macro `entrait` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0706]: functions in traits cannot be declared `async`
  --> examples/axum/src/main.rs:15:5
   |
15 |     async fn get_foo() -> Foo {
   |     -----^^^^^^^^^^^^^^^^^^^^
   |     |
   |     `async` because of this
   |
   = note: `async` trait functions are not currently supported
   = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
   = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information

error[E0277]: the trait bound `fn(Extension<A>) -> impl Future<Output = Json<Foo>> {Routes::<A>::get_foo}: Handler<_, _>` is not satisfied
   --> examples/axum/src/main.rs:36:51
    |
36  |             axum::Router::new().route("/foo", get(Self::get_foo))
    |                                               --- ^^^^^^^^^^^^^ the trait `Handler<_, _>` is not implemented for fn item `fn(Extension<A>) -> impl Future<Output = Json<Foo>> {Routes::<A>::get_foo}`
    |                                               |
    |                                               required by a bound introduced by this call
    |
    = help: the trait `Handler<T, ReqBody>` is implemented for `Layered<S, T>`
note: required by a bound in `axum::routing::get`
   --> /home/dkolsoi/.cargo/registry/src/github.com-1ecc6299db9ec823/axum-0.5.17/src/routing/method_routing.rs:397:1
    |
397 | 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)
audunhalland commented 1 year ago

Because these examples use async trait methods, we have to select an "async strategy". Building with --features boxed-futures should work: cargo test --all --features boxed-futures works for me. This will correctly re-export the async-trait crate.

The bug is that this feature is not explicitly requested from the example Cargo.toml(s).

TheDan64 commented 1 year ago

Ah okay, yeah - it'd be great if the example worked out of the box without having to be aware of a missing feature flag

audunhalland commented 1 year ago

Agreed, but I think there was at least one reason for not including the feature: To test as many feature configurations as possible. Requesting a lib feature from the examples turns that feature on everywhere else in the workspace.

But now I found out that CI doesn't even build the examples, so apparently it's not so hard to fix after all. CI can just build the examples as a separate step.

audunhalland commented 1 year ago

released 0.5.1 with this fix.