#future #async

nightly back-to-the-future

Conversions between std::future::Future and futures::Future

8 releases

0.1.7 Apr 17, 2019
0.1.6 Apr 17, 2019
0.1.5 Dec 31, 2018

#1196 in Asynchronous


143 lines

Documentation crates.io Build Status


std and futures interoperability

This crate implements adapters for the two different future types: std::future::Future and futures::Future. You can seamlessly convert the one into the other. The aim is to be able to use new async/await syntax with existing futures::Future infrastructure, such as tokio.

Keep in mind that many of the used features are still unstable and only available on nightly with feature gates.

A simple example:


use std::time::{Duration, Instant};
use tokio::timer::Delay;

use back_to_the_future::{futures_await, BoxIntoFutures};

fn main() {
  let f = async {
    // Await an old futures::Future using the futures_await! macro.
    // This macro wraps the future in an adapter behind the scenes.
    futures_await!(Delay::new(Instant::now() + Duration::new(0, 10))).unwrap();

  // Convert the std::future::Future into a futures::Future so that tokio::run can use it.