refactor(compat): use pub(super) to remove compat_impl modules
This commit is contained in:
		| @@ -1,6 +1,55 @@ | ||||
| //! Wrappers to build compatibility with the `http` crate. | ||||
|  | ||||
| pub use super::compat_impl::{ | ||||
|     CompatClient, | ||||
|     CompatFutureResponse | ||||
| }; | ||||
| use futures::{Future, Poll, Stream}; | ||||
| use http; | ||||
| use tokio_service::Service; | ||||
|  | ||||
| use client::{Connect, Client, FutureResponse}; | ||||
| use error::Error; | ||||
| use proto::Body; | ||||
|  | ||||
| /// A Client to make outgoing HTTP requests. | ||||
| #[derive(Debug)] | ||||
| pub struct CompatClient<C, B = Body> { | ||||
|     inner: Client<C, B> | ||||
| } | ||||
|  | ||||
| pub(super) fn client<C, B>(client: Client<C, B>) -> CompatClient<C, B> { | ||||
|     CompatClient { inner: client } | ||||
| } | ||||
|  | ||||
| impl<C, B> Service for CompatClient<C, B> | ||||
| where C: Connect, | ||||
|       B: Stream<Error=Error> + 'static, | ||||
|       B::Item: AsRef<[u8]>, | ||||
| { | ||||
|     type Request = http::Request<B>; | ||||
|     type Response = http::Response<Body>; | ||||
|     type Error = Error; | ||||
|     type Future = CompatFutureResponse; | ||||
|  | ||||
|     fn call(&self, req: Self::Request) -> Self::Future { | ||||
|         future(self.inner.call(req.into())) | ||||
|     } | ||||
| } | ||||
|  | ||||
| /// A `Future` that will resolve to an `http::Response`. | ||||
| #[must_use = "futures do nothing unless polled"] | ||||
| #[derive(Debug)] | ||||
| pub struct CompatFutureResponse { | ||||
|     inner: FutureResponse | ||||
| } | ||||
|  | ||||
| pub(super) fn future(fut: FutureResponse) -> CompatFutureResponse { | ||||
|     CompatFutureResponse { inner: fut } | ||||
| } | ||||
|  | ||||
| impl Future for CompatFutureResponse { | ||||
|     type Item = http::Response<Body>; | ||||
|     type Error = Error; | ||||
|  | ||||
|     fn poll(&mut self) -> Poll<Self::Item, Error> { | ||||
|         self.inner.poll() | ||||
|             .map(|a| a.map(|r| r.into())) | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,53 +0,0 @@ | ||||
| use futures::{Future, Poll, Stream}; | ||||
| use http; | ||||
| use tokio_service::Service; | ||||
|  | ||||
| use client::{Connect, Client, FutureResponse}; | ||||
| use error::Error; | ||||
| use proto::Body; | ||||
|  | ||||
| /// A Client to make outgoing HTTP requests. | ||||
| #[derive(Debug)] | ||||
| pub struct CompatClient<C, B = Body> { | ||||
|     inner: Client<C, B> | ||||
| } | ||||
|  | ||||
| pub fn client<C, B>(client: Client<C, B>) -> CompatClient<C, B> { | ||||
|     CompatClient { inner: client } | ||||
| } | ||||
|  | ||||
| impl<C, B> Service for CompatClient<C, B> | ||||
| where C: Connect, | ||||
|       B: Stream<Error=Error> + 'static, | ||||
|       B::Item: AsRef<[u8]>, | ||||
| { | ||||
|     type Request = http::Request<B>; | ||||
|     type Response = http::Response<Body>; | ||||
|     type Error = Error; | ||||
|     type Future = CompatFutureResponse; | ||||
|  | ||||
|     fn call(&self, req: Self::Request) -> Self::Future { | ||||
|         future(self.inner.call(req.into())) | ||||
|     } | ||||
| } | ||||
|  | ||||
| /// A `Future` that will resolve to an `http::Response`. | ||||
| #[must_use = "futures do nothing unless polled"] | ||||
| #[derive(Debug)] | ||||
| pub struct CompatFutureResponse { | ||||
|     inner: FutureResponse | ||||
| } | ||||
|  | ||||
| pub fn future(fut: FutureResponse) -> CompatFutureResponse { | ||||
|     CompatFutureResponse { inner: fut } | ||||
| } | ||||
|  | ||||
| impl Future for CompatFutureResponse { | ||||
|     type Item = http::Response<Body>; | ||||
|     type Error = Error; | ||||
|  | ||||
|     fn poll(&mut self) -> Poll<Self::Item, Error> { | ||||
|         self.inner.poll() | ||||
|             .map(|a| a.map(|r| r.into())) | ||||
|     } | ||||
| } | ||||
| @@ -32,8 +32,6 @@ mod connect; | ||||
| mod dns; | ||||
| mod pool; | ||||
| #[cfg(feature = "compat")] | ||||
| mod compat_impl; | ||||
| #[cfg(feature = "compat")] | ||||
| pub mod compat; | ||||
|  | ||||
| /// A Client to make outgoing HTTP requests. | ||||
| @@ -121,13 +119,13 @@ where C: Connect, | ||||
|     #[inline] | ||||
|     #[cfg(feature = "compat")] | ||||
|     pub fn request_compat(&self, req: http::Request<B>) -> compat::CompatFutureResponse { | ||||
|         self::compat_impl::future(self.call(req.into())) | ||||
|         self::compat::future(self.call(req.into())) | ||||
|     } | ||||
|  | ||||
|     /// Convert into a client accepting `http::Request`. | ||||
|     #[cfg(feature = "compat")] | ||||
|     pub fn into_compat(self) -> compat::CompatClient<C, B> { | ||||
|         self::compat_impl::client(self) | ||||
|         self::compat::client(self) | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user