diff --git a/src/connector.rs b/src/connector.rs index 6bf949cf..d1006ac4 100644 --- a/src/connector.rs +++ b/src/connector.rs @@ -150,6 +150,51 @@ impl Future for ConnectorFuture { } } +pub struct DefaultConnector(Connector); + +impl Default for DefaultConnector { + fn default() -> Self { + DefaultConnector(Connector::default()) + } +} + +impl DefaultConnector { + pub fn new(cfg: ResolverConfig, opts: ResolverOpts) -> Self { + DefaultConnector(Connector::new(cfg, opts)) + } +} + +impl Service for DefaultConnector { + type Request = T; + type Response = TcpStream; + type Error = ConnectorError; + type Future = DefaultConnectorFuture; + + fn poll_ready(&mut self) -> Poll<(), Self::Error> { + self.0.poll_ready() + } + + fn call(&mut self, req: Self::Request) -> Self::Future { + DefaultConnectorFuture { + fut: self.0.call(req), + } + } +} + +#[doc(hidden)] +pub struct DefaultConnectorFuture { + fut: ConnectorFuture, +} + +impl Future for DefaultConnectorFuture { + type Item = TcpStream; + type Error = ConnectorError; + + fn poll(&mut self) -> Poll { + Ok(Async::Ready(try_ready!(self.fut.poll()).2)) + } +} + /// Resolver future struct ResolveFut { req: Option, diff --git a/src/lib.rs b/src/lib.rs index d7c0fed5..f6a061a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,6 +21,7 @@ extern crate log; extern crate bytes; #[macro_use] extern crate failure; +#[macro_use] extern crate futures; extern crate mio; extern crate net2;