Difficulty running an example from a crate inside my own project

I'm trying to use the shiplift crate to run some simple Docker commands within some Rust code.

The examples seem to work fine:

$ git clone git@github.com:softprops/shiplift.git
$ cd shiplift
$ git checkout v6.0.0
$ cargo run --example images
sha256:[clipped] 2020-08-04 15:42:34 UTC ["debian:buster"]
sha256:[clipped] 2020-06-03 19:50:59 UTC ["python:3.8-alpine"]
sha256:[clipped] 2019-06-27 22:56:27 UTC ["python:3.7.3-alpine"]
sha256:[clipped] 2019-03-07 22:19:53 UTC ["alpine:3.7"]
sha256:[clipped] 2019-01-01 01:29:27 UTC ["hello-world:latest"]
[…]

However, I can't seem to get it to work inside my own cargo project:

$ cargo new --vcs git --lib --edition 2018 testytest
$ cd testytest
$ mkdir examples
$ cp ../shiplift/examples/images.rs examples
$ cat >>Cargo.toml <<EOF
shiplift = "0.6"
futures = "0.3.1"
tokio = { version = "0.2.6", features = ["macros"] }
EOF
$ cargo run --example images
error[E0432]: unresolved import `tokio::prelude::Future`
 --> examples/images.rs:2:5
  |
2 | use tokio::prelude::Future;
  |     ^^^^^^^^^^^^^^^^^^^^^^ no `Future` in `prelude`

error[E0425]: cannot find function `run` in crate `tokio`
  --> examples/images.rs:21:12
   |
21 |     tokio::run(fut);
   |            ^^^ not found in `tokio`

error[E0599]: no method named `map` found for opaque type `impl futures::future::Future` in the current scope
  --> examples/images.rs:10:10
   |
10 |         .map(|images| {
   |          ^^^ method not found in `impl futures::future::Future`
   |
   = note: the method `map` exists but the following trait bounds were not satisfied:
           `impl futures::future::Future: std::iter::Iterator`
           which is required by `&mut impl futures::future::Future: 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:
   |
1  | use futures::future::Future;
   |

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0425, E0432, E0599.
For more information about an error, try `rustc --explain E0425`.
error: could not compile `testytest2`.

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

I spent a while trying to fix this error by editing examples/images.rs but I couldn't figure out what was going wrong.

The tokio::run and tokio::prelude::Future things highlight that the code you are trying uses Tokio version 0.1.x rather than 0.2.x.

I just checked out v0.6.0 and it looks like they are using an old version of tokio like @alice said.

[dependencies]
...
futures = "0.1"
...
tokio = "0.1"
tokio-codec = "0.1"
tokio-io = "0.1"

If you check out the latest master the examples work fine using tokio 0.2.0.

Ahh, that is it! If I instead run:

$ cat >>Cargo.toml <<EOF
shiplift = "0.6"
futures = "0.3.1"
tokio = "0.1"
EOF

then it works fine!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.