]> git.lizzy.rs Git - rust.git/commit - src/tools/miri
Rollup merge of #72303 - yoshuawuyts:future-poll-fn, r=dtolnay
authorManish Goregaokar <manishsmail@gmail.com>
Sat, 11 Jul 2020 06:26:24 +0000 (23:26 -0700)
committerGitHub <noreply@github.com>
Sat, 11 Jul 2020 06:26:24 +0000 (23:26 -0700)
commitd82588b45aa866418a3cc88924e939015fd1bd1c
treeeed55c32d102df6ab06e88937e385ac7e04a1a88
parentec1e7e9dbc83e57da7809cfc32c01e881b42555b
parenta31f103fd27bde3f83b9dd54af8e41d64e5001f4
Rollup merge of #72303 - yoshuawuyts:future-poll-fn, r=dtolnay

Add core::future::{poll_fn, PollFn}

This is a sibling PR to #70834, adding `future::poll_fn`. This is a small helper function that helps bridge the gap between "poll state machines" and "async/await". It was first introduced in [futures@0.1.7](https://docs.rs/futures/0.1.7/futures/future/fn.poll_fn.html) in December of 2016, and has been tried and tested as part of the ecosystem for the past 3.5 years.

## Implementation

Much of the same reasoning from #70834 applies: by returning a concrete struct rather than an `async fn` we get to mark the future as `Unpin`. It also becomes named which allows storing it in structs without boxing. This implementation has been modified from the implementation in `futures-rs`.

## References
- [`futures::future::poll_fn`](https://docs.rs/futures/0.3.5/futures/future/fn.poll_fn.html)
- [`async_std::future::poll_fn`](https://docs.rs/async-std/1.5.0/async_std/future/fn.poll_fn.html)
src/libcore/future/mod.rs