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