use core::pin::Pin;
use futures_core::future::{FusedFuture, Future};
use futures_core::task::{Context, Poll};
#[derive(Debug, Clone)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Ready<T>(Option<T>);
impl<T> Ready<T> {
#[inline]
pub fn into_inner(mut self) -> T {
self.0.take().unwrap()
}
}
impl<T> Unpin for Ready<T> {}
impl<T> FusedFuture for Ready<T> {
fn is_terminated(&self) -> bool {
self.0.is_none()
}
}
impl<T> Future for Ready<T> {
type Output = T;
#[inline]
fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<T> {
Poll::Ready(self.0.take().expect("Ready polled after completion"))
}
}
pub fn ready<T>(t: T) -> Ready<T> {
Ready(Some(t))
}
pub fn ok<T, E>(t: T) -> Ready<Result<T, E>> {
Ready(Some(Ok(t)))
}
pub fn err<T, E>(err: E) -> Ready<Result<T, E>> {
Ready(Some(Err(err)))
}