use futures::{Future, Poll};
use http_connection::HttpConnection;
use tokio_io::{AsyncRead, AsyncWrite};
use tower_service::Service;
pub trait HttpMakeConnection<Target>: sealed::Sealed<Target> {
type Connection: HttpConnection + AsyncRead + AsyncWrite;
type Error;
type Future: Future<Item = Self::Connection, Error = Self::Error>;
fn poll_ready(&mut self) -> Poll<(), Self::Error>;
fn make_connection(&mut self, target: Target) -> Self::Future;
}
impl<C, Target> sealed::Sealed<Target> for C where C: Service<Target> {}
impl<C, Target> HttpMakeConnection<Target> for C
where
C: Service<Target>,
C::Response: HttpConnection + AsyncRead + AsyncWrite,
{
type Connection = C::Response;
type Error = C::Error;
type Future = C::Future;
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
Service::poll_ready(self)
}
fn make_connection(&mut self, target: Target) -> Self::Future {
Service::call(self, target)
}
}
mod sealed {
pub trait Sealed<Target> {}
}