The Rust Future module defines many ways to chain and convert futures. This post summarises a few common ones as a reference table.
- the result types below are given as
Future<T>but this is not accurate. For example,
Lazy<T>and so on. But these can be used as if they were
Future<Output=T>. For my purposes this shorthand works, as I want to think of them as futures I can
awaiton or combine with other futures.
- I’ve used
Vecin the table below for arguments, where the more general iterator is acceptable. I’ve done this to keep the table short.
There is a playground with a few of these functions as an example.
use futures::future to bring these functions into scope.
See the Future module for the complete list.
Combinators available via
These require a
use futures::future::FutureExt; statement, and are functions on a
There are many more in the FutureExt module.
Combinators to simplify working with futures that carry
Some of these functions need a
use futures::future::TryFutureExt; statement to bring them into scope.
See the TryFutureExt module for more.