1 use super::error;
2 use futures_core::ready;
3 use pin_project_lite::pin_project;
4 use std::{
5     future::Future,
6     pin::Pin,
7     task::{Context, Poll},
8 };
9 
10 pin_project! {
11     /// Response future returned by [`Optional`].
12     ///
13     /// [`Optional`]: crate::util::Optional
14     #[derive(Debug)]
15     pub struct ResponseFuture<T> {
16         #[pin]
17         inner: Option<T>,
18     }
19 }
20 
21 impl<T> ResponseFuture<T> {
new(inner: Option<T>) -> ResponseFuture<T>22     pub(crate) fn new(inner: Option<T>) -> ResponseFuture<T> {
23         ResponseFuture { inner }
24     }
25 }
26 
27 impl<F, T, E> Future for ResponseFuture<F>
28 where
29     F: Future<Output = Result<T, E>>,
30     E: Into<crate::BoxError>,
31 {
32     type Output = Result<T, crate::BoxError>;
33 
poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>34     fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
35         match self.project().inner.as_pin_mut() {
36             Some(inner) => Poll::Ready(Ok(ready!(inner.poll(cx)).map_err(Into::into)?)),
37             None => Poll::Ready(Err(error::None::new().into())),
38         }
39     }
40 }
41