actix / book

Actix user guides
https://actix.rs/docs/actix
Apache License 2.0
187 stars 60 forks source link

Example from the Arbiter chapter fails to compile #43

Closed f8122dac closed 4 years ago

f8122dac commented 4 years ago

The example in arbiter chapter does not compile.

I'm compiling on rust nightly rustc 1.43.0-nightly (8aa9d2014 2020-02-21)

warning: unused import: `futures::Future`
 --> src/main.rs:4:5
  |
4 | use futures::Future;
  |     ^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0599]: no method named `map_err` found for struct `actix::prelude::Request<SumActor, Value>` in the current scope
  --> src/main.rs:63:10
   |
63 |         .map_err(|e| {
   |          ^^^^^^^ method not found in `actix::prelude::Request<SumActor, Value>`
   |
   = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
   |
3  | use crate::futures::TryFutureExt;
   |

error[E0599]: no method named `map` found for struct `actix::prelude::Request<DisplayActor, Display>` in the current scope
  --> src/main.rs:74:41
   |
74 |             dis_addr.send(Display(res)).map(move |_| ()).map_err(|_| ())
   |                                         ^^^ method not found in `actix::prelude::Request<DisplayActor, Display>`
   |
   = note: the method `map` exists but the following trait bounds were not satisfied:
           `&mut actix::prelude::Request<DisplayActor, Display> : std::iter::Iterator`
   = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
   |
3  | use crate::futures::FutureExt;
   |

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0599`.
error: could not compile `actix-middleware-tryout`.

To learn more, run the command again with --verbose.

Tried adding suggested use statements, but no luck.

warning: unused import: `futures::Future`
 --> src/main.rs:4:5
  |
4 | use futures::Future;
  |     ^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0599]: no method named `map_err` found for struct `futures::future::Map<actix::prelude::Request<DisplayActor, Display>, [closure@src/main.rs:76:45: 76:56]>` in the current scope
  --> src/main.rs:76:58
   |
76 |             dis_addr.send(Display(res)).map(move |_| ()).map_err(|_| ())
   |                                                          ^^^^^^^ method not found in `futures::future::Map<actix::prelude::Request<DisplayActor, Display>, [closure@src/main.rs:76:45: 76:56]>`
   |
   = note: the method `map_err` exists but the following trait bounds were not satisfied:
           `&futures::future::Map<actix::prelude::Request<DisplayActor, Display>, [closure@src/main.rs:76:45: 76:56]> : futures::TryFutureExt`
           `&mut futures::future::Map<actix::prelude::Request<DisplayActor, Display>, [closure@src/main.rs:76:45: 76:56]> : futures::TryFutureExt`
           `futures::future::Map<actix::prelude::Request<DisplayActor, Display>, [closure@src/main.rs:76:45: 76:56]> : futures::TryFutureExt`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.
error: could not compile `actix-middleware-tryout`.

To learn more, run the command again with --verbose.
f8122dac commented 4 years ago

The playground on the book's web interface seems to through error as well, looks like actix is not found:

   Compiling playground v0.0.1 (/playground)
error[E0463]: can't find crate for `actix`
 --> src/main.rs:1:1
  |
1 | extern crate actix;
  | ^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `playground`.

To learn more, run the command again with --verbose.
JohnTitor commented 4 years ago

Could you check if your deps are the same as here?:

https://github.com/actix/book/blob/2d6a0c1274330e690c2e0e54a936454376f9641f/Cargo.toml#L21-L41

f8122dac commented 4 years ago

Thank you @JohnTitor. My Cargo.toml had actix = "0.9.0" and future = "0.3.4". And the versions suggested by the Cargo.toml file you pointed out did compile.

I'm curious why this fails to compile in newer versions? Should I use this combination of actix and futures versions instead of newer versions to use map and map_err?

JohnTitor commented 4 years ago

Because there is no compatibility between futures 0.1 and 0.3 (i.e. actix 0.7 and 0.9). Indeed we should update this book to the latest but I don't have bandwidth right now. You can see docs.rs or examples on actix repo when using actix 0.9. I'm going to close this issue as the current doc is correct.