use super::error; use futures_core::ready; use pin_project_lite::pin_project; use std::{ future::Future, pin::Pin, task::{Context, Poll}, }; pin_project! { /// Response future returned by [`Optional`]. /// /// [`Optional`]: crate::util::Optional #[derive(Debug)] pub struct ResponseFuture { #[pin] inner: Option, } } impl ResponseFuture { pub(crate) fn new(inner: Option) -> ResponseFuture { ResponseFuture { inner } } } impl Future for ResponseFuture where F: Future>, E: Into, { type Output = Result; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { match self.project().inner.as_pin_mut() { Some(inner) => Poll::Ready(Ok(ready!(inner.poll(cx)).map_err(Into::into)?)), None => Poll::Ready(Err(error::None::new().into())), } } }