diff --git a/src/client/connect/mod.rs b/src/client/connect/mod.rs index 5cb051ab14..178cae8b93 100644 --- a/src/client/connect/mod.rs +++ b/src/client/connect/mod.rs @@ -83,6 +83,7 @@ pub mod dns; mod http; #[cfg(feature = "tcp")] pub use self::http::{HttpConnector, HttpInfo}; +pub use self::sealed::Connect; /// Describes a type returned by a connector. pub trait Connection { @@ -258,31 +259,52 @@ pub(super) mod sealed { // The `Sized` bound is to prevent creating `dyn Connect`, since they cannot // fit the `Connect` bounds because of the blanket impl for `Service`. pub trait Connect: Sealed + Sized { - /// The connected IO Stream. - type Transport: AsyncRead + AsyncWrite + Connection; - /// An error occured when trying to connect. - type Error: Into>; - /// A Future that will resolve to the connected Transport. - type Future: Future>; #[doc(hidden)] + type _Svc: ConnectSvc; + #[doc(hidden)] + fn connect(self, internal_only: Internal, dst: Uri) -> ::Future; + } + + pub trait ConnectSvc { + type Connection: AsyncRead + AsyncWrite + Connection + Unpin + Send + 'static; + type Error: Into>; + type Future: Future> + Unpin + Send + 'static; + fn connect(self, internal_only: Internal, dst: Uri) -> Self::Future; } impl Connect for S where - S: tower_service::Service + Send, + S: tower_service::Service + Send + 'static, + S::Error: Into>, + S::Future: Unpin + Send, + T: AsyncRead + AsyncWrite + Connection + Unpin + Send + 'static, + { + type _Svc = S; + + fn connect(self, _: Internal, dst: Uri) -> crate::service::Oneshot { + crate::service::oneshot(self, dst) + } + } + + impl ConnectSvc for S + where + S: tower_service::Service + Send + 'static, S::Error: Into>, S::Future: Unpin + Send, T: AsyncRead + AsyncWrite + Connection + Unpin + Send + 'static, { - type Transport = T; + type Connection = T; type Error = S::Error; type Future = crate::service::Oneshot; + fn connect(self, _: Internal, dst: Uri) -> Self::Future { crate::service::oneshot(self, dst) } } + + impl Sealed for S where S: tower_service::Service + Send, diff --git a/src/client/mod.rs b/src/client/mod.rs index 851e17e6a8..5f652fb042 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -150,8 +150,6 @@ impl Client<(), Body> { impl Client where C: Connect + Clone + Send + Sync + 'static, - C::Transport: Unpin + Send + 'static, - C::Future: Unpin + Send + 'static, B: Payload + Send + 'static, B::Data: Send, { @@ -548,8 +546,6 @@ where impl tower_service::Service> for Client where C: Connect + Clone + Send + Sync + 'static, - C::Transport: Unpin + Send + 'static, - C::Future: Unpin + Send + 'static, B: Payload + Send + 'static, B::Data: Send, {