1 //! `poll_fn` reimplementation as it is otherwise the only thing we need from the futures crate.
3 //! Our `futures` crate dependency is optional.
5 use std
::future
::Future
;
7 use std
::task
::{Context, Poll}
;
13 pub fn poll_fn
<F
, R
>(func
: F
) -> PollFn
<F
>
15 F
: FnMut(&mut Context
) -> Poll
<R
>,
17 PollFn { func: Some(func) }
20 impl<F
, R
> Future
for PollFn
<F
>
22 F
: FnMut(&mut Context
) -> Poll
<R
>,
26 fn poll(self: Pin
<&mut Self>, cx
: &mut Context
) -> Poll
<Self::Output
> {
27 let this
= unsafe { self.get_unchecked_mut() }
;
28 match &mut this
.func
{
29 None
=> panic
!("poll() after Ready"),