2019-04-08 20:11:09 -07:00
|
|
|
use crate::Error;
|
2019-09-10 08:48:01 -07:00
|
|
|
use pin_project::pin_project;
|
|
|
|
use std::{
|
|
|
|
future::Future,
|
|
|
|
pin::Pin,
|
|
|
|
task::{Context, Poll},
|
|
|
|
};
|
2019-03-08 08:46:12 -08:00
|
|
|
|
2019-09-10 08:48:01 -07:00
|
|
|
#[pin_project]
|
2019-03-08 08:46:12 -08:00
|
|
|
pub struct ResponseFuture<F> {
|
2019-09-10 08:48:01 -07:00
|
|
|
#[pin]
|
2019-03-08 08:46:12 -08:00
|
|
|
inner: F,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<F> ResponseFuture<F> {
|
|
|
|
pub(crate) fn new(inner: F) -> Self {
|
|
|
|
ResponseFuture { inner }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-10 08:48:01 -07:00
|
|
|
impl<F, T, E> Future for ResponseFuture<F>
|
2019-03-08 08:46:12 -08:00
|
|
|
where
|
2019-09-10 08:48:01 -07:00
|
|
|
F: Future<Output = Result<T, E>>,
|
|
|
|
E: Into<Error>,
|
2019-03-08 08:46:12 -08:00
|
|
|
{
|
2019-09-10 08:48:01 -07:00
|
|
|
type Output = Result<T, Error>;
|
2019-03-08 08:46:12 -08:00
|
|
|
|
2019-09-10 08:48:01 -07:00
|
|
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
|
|
|
self.project().inner.poll(cx).map_err(Into::into)
|
2019-03-08 08:46:12 -08:00
|
|
|
}
|
|
|
|
}
|