How to use old 0.1 futures in new codebase


There are libraries that did not migrate to futures 0.3, namely tokio-ping. There's an example:

    let pinger = tokio_ping::Pinger::new();
    let stream = pinger.and_then(move |pinger| Ok(pinger.chain(addr).stream()));

that gives an error:

90 |         let stream = pinger.and_then(move |pinger| Ok(pinger.chain(ip).stream()));
   |                             ^^^^^^^^ method not found in `impl futures::future::Future`

So, the question is: how do I use older futures in recent tokio (0.2.21)? Can I somehow convert older futures to newer in application code?

Side question: do you know any ping libraries using new async syntax?

futures 0.3 has a compat feature, which enables a bunch of "futures 0.1" <-> "futures 0.3" combinators. I've used it successfully for some projects before. However, I don't know how robust it general, especially if the other project depends on a specific executor, like tokio 0.1 - doing this might end up with errors about not being in an executor context, or it might end up with just running both the tokio 0.1 and tokio 0.2 executors.

There's a blog post which explains more of the compat layer, and gives a short demonstration here:


The tokio-compat crate has tools for things tied to Tokio (and a reexport of compat from futures).

1 Like

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.