use futures::{Future, Poll};
use http;
pub trait HttpFuture: sealed::Sealed {
type Body;
fn poll_http(&mut self) -> Poll<http::Response<Self::Body>, ::Error>;
fn lift(self) -> LiftFuture<Self>
where Self: Sized,
{
LiftFuture { inner: self }
}
}
#[derive(Debug)]
pub struct LiftFuture<T> {
inner: T,
}
impl<T, B> HttpFuture for T
where T: Future<Item = http::Response<B>, Error = ::Error>
{
type Body = B;
fn poll_http(&mut self) -> Poll<http::Response<Self::Body>, ::Error> {
Future::poll(self)
}
}
impl<T, B> sealed::Sealed for T
where T: Future<Item = http::Response<B>, Error = ::Error>
{
}
impl<T: HttpFuture> Future for LiftFuture<T> {
type Item = http::Response<T::Body>;
type Error = ::Error;
fn poll(&mut self) -> Poll<Self::Item, ::Error> {
self.inner.poll_http()
}
}
pub(crate) mod sealed {
pub trait Sealed {}
}