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