use std::{ future::Future, pin::Pin, task::{Context, Poll}, }; // TODO: replace with `std::future::poll_fn` once MSRV >= 1.64 pub(crate) fn poll_fn(f: F) -> PollFn where F: FnMut(&mut Context<'_>) -> Poll, { PollFn { f } } pub(crate) struct PollFn { f: F, } impl Unpin for PollFn {} impl Future for PollFn where F: FnMut(&mut Context<'_>) -> Poll, { type Output = T; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { (self.f)(cx) } }