]> git.lizzy.rs Git - rust.git/commitdiff
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)
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)

1  2 
src/libcore/future/mod.rs

index 2555d91ae8d9a287a60d256ebc5adecae70eda38,f56d19d66248aab4feffc81de6acc22c5e30d0c6..6d1ad9db74435fca5d1afa81b57ff0283faea49d
@@@ -10,8 -10,8 +10,9 @@@ use crate::
  };
  
  mod future;
 +mod into_future;
  mod pending;
+ mod poll_fn;
  mod ready;
  
  #[stable(feature = "futures_api", since = "1.36.0")]