use core::fmt;
use core::pin::Pin;
use core::future::Future;
use core::task::{Context, Poll};
#[macro_export]
#[deprecated(since = "0.2.4", note = "use `core::pin::pin` instead")]
macro_rules! pin_mut {
($($x:ident),* $(,)?) => { $(
let mut $x = $x;
#[allow(unused_mut)]
let mut $x = unsafe {
core::pin::Pin::new_unchecked(&mut $x)
};
)* }
}
pub(crate) fn assert_future<T, F>(future: F) -> F
where
F: Future<Output = T>,
{
future
}
#[deprecated(since = "0.2.4", note = "use `core::future::PollFn` instead")]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct PollFn<F> {
f: F,
}
impl<F> Unpin for PollFn<F> {}
#[deprecated(since = "0.2.4", note = "use `core::future::poll_fn` instead")]
pub fn poll_fn<T, F>(f: F) -> PollFn<F>
where
F: FnMut(&mut Context<'_>) -> Poll<T>
{
assert_future::<T, _>(PollFn { f })
}
impl<F> fmt::Debug for PollFn<F> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("PollFn").finish()
}
}
impl<T, F> Future for PollFn<F>
where F: FnMut(&mut Context<'_>) -> Poll<T>,
{
type Output = T;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> {
(&mut self.f)(cx)
}
}