back-to-the-future

Crates.ioback-to-the-future
lib.rsback-to-the-future
version0.1.7
sourcesrc
created_at2018-12-23 22:39:18.414366
updated_at2019-04-17 18:16:25.606059
descriptionConversions between std::future::Future and futures::Future.
homepage
repositoryhttps://github.com/de-vri-es/back-to-the-future
max_upload_size
id103510
size12,923
Maarten de Vries (de-vri-es)

documentation

https://docs.rs/back-to-the-future

README

Documentation crates.io Build Status

back-to-the-future

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:

#![feature(async_await)]
#![feature(await_macro)]
#![feature(futures_api)]

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();
    Ok(())
  };

  // Convert the std::future::Future into a futures::Future so that tokio::run can use it.
  tokio::run(f.box_into_futures());
}
Commit count: 21

cargo fmt