hyper_util/common/
future.rs

1use std::{
2    future::Future,
3    pin::Pin,
4    task::{Context, Poll},
5};
6
7// TODO: replace with `std::future::poll_fn` once MSRV >= 1.64
8pub(crate) fn poll_fn<T, F>(f: F) -> PollFn<F>
9where
10    F: FnMut(&mut Context<'_>) -> Poll<T>,
11{
12    PollFn { f }
13}
14
15pub(crate) struct PollFn<F> {
16    f: F,
17}
18
19impl<F> Unpin for PollFn<F> {}
20
21impl<T, F> Future for PollFn<F>
22where
23    F: FnMut(&mut Context<'_>) -> Poll<T>,
24{
25    type Output = T;
26
27    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
28        (self.f)(cx)
29    }
30}