1use futures::{try_ready, Async, Future, Poll};
4use hyper::client::connect::Connect;
5use tower_service::Service;
6
7pub use hyper::client::connect::{Destination, HttpConnector};
8
9#[derive(Debug)]
24pub struct Connector<C> {
25 inner: C,
26}
27
28#[derive(Debug)]
31pub struct ConnectorFuture<C>
32where
33 C: Connect,
34{
35 inner: C::Future,
36}
37
38impl<C> Connector<C>
39where
40 C: Connect,
41{
42 pub fn new(inner: C) -> Self {
44 Connector { inner }
45 }
46}
47
48impl<C> Service<Destination> for Connector<C>
49where
50 C: Connect,
51{
52 type Response = C::Transport;
53 type Error = C::Error;
54 type Future = ConnectorFuture<C>;
55
56 fn poll_ready(&mut self) -> Poll<(), Self::Error> {
57 Ok(().into())
58 }
59
60 fn call(&mut self, target: Destination) -> Self::Future {
61 let fut = self.inner.connect(target);
62 ConnectorFuture { inner: fut }
63 }
64}
65
66impl<C> Future for ConnectorFuture<C>
67where
68 C: Connect,
69{
70 type Item = C::Transport;
71 type Error = C::Error;
72
73 fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
74 let (transport, _) = try_ready!(self.inner.poll());
75
76 Ok(Async::Ready(transport))
77 }
78}