diff --git a/tonic/src/transport/channel/endpoint.rs b/tonic/src/transport/channel/endpoint.rs index 8cd3e9d9e..5bd933567 100644 --- a/tonic/src/transport/channel/endpoint.rs +++ b/tonic/src/transport/channel/endpoint.rs @@ -334,6 +334,27 @@ impl Endpoint { } } + /// Connect with a custom connector lazily. + /// + /// This allows you to build a [Channel](struct.Channel.html) that uses a non-HTTP transport. + /// See the `uds` example for an example on how to use this function to build channel that + /// uses a Unix socket transport. + pub async fn connect_with_connector_lazy(&self, connector: C) -> Result + where + C: MakeConnection + Send + 'static, + C::Connection: Unpin + Send + 'static, + C::Future: Send + 'static, + crate::Error: From + Send + 'static, + { + #[cfg(feature = "tls")] + let connector = service::connector(connector, self.tls.clone()); + + #[cfg(not(feature = "tls"))] + let connector = service::connector(connector); + + Ok(Channel::new(connector, self.clone())) + } + /// Get the endpoint uri. /// /// ```