From 96b1f87dfbd1dfa0f6a061990f0745323b056291 Mon Sep 17 00:00:00 2001 From: Constantin Nickel Date: Thu, 15 Oct 2020 11:13:26 +0200 Subject: [PATCH] Tune tokio's feature gates to play nice together --- src/tokio.rs | 61 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/src/tokio.rs b/src/tokio.rs index 11f0081..afe5ed6 100644 --- a/src/tokio.rs +++ b/src/tokio.rs @@ -11,7 +11,7 @@ use super::{domain, port, WebSocketStream}; use futures_io::{AsyncRead, AsyncWrite}; -#[cfg(feature = "tokio-rustls")] +#[cfg(all(feature = "tokio-rustls", not(feature = "tokio-native-tls")))] pub(crate) mod tokio_tls { use real_tokio_rustls::{client::TlsStream, TlsConnector as AsyncTlsConnector}; use real_tokio_rustls::rustls::ClientConfig; @@ -167,7 +167,10 @@ pub(crate) mod tokio_tls { } } -#[cfg(feature = "tokio-openssl")] +#[cfg(all( + feature = "tokio-openssl", + not(any(feature = "tokio-native-tls", feature = "tokio-rustls")) +))] pub(crate) mod tokio_tls { use openssl::ssl::{ConnectConfiguration, SslConnector, SslMethod}; use real_tokio_openssl::connect; @@ -324,7 +327,14 @@ pub(crate) mod dummy_tls { )))] use self::dummy_tls::{client_async_tls_with_connector_and_config, AutoStream}; -#[cfg(all(feature = "async-tls", not(feature = "tokio-native-tls")))] +#[cfg(all( + feature = "async-tls", + not(any( + feature = "tokio-rustls", + feature = "tokio-native-tls", + feature = "tokio-openssl" + )) +))] pub(crate) mod async_tls_adapter { use super::{ Error, IntoClientRequest, Response, TokioAdapter, WebSocketConfig, WebSocketStream, @@ -361,22 +371,37 @@ pub(crate) mod async_tls_adapter { pub type AutoStream = MaybeTlsStream>; } -#[cfg(all(feature = "async-tls", not(any(feature = "tokio-native-tls", feature = "tokio-openssl"))))] + +#[cfg(all( + feature = "async-tls", + not(any( + feature = "tokio-rustls", + feature = "tokio-native-tls", + feature = "tokio-openssl" + )) +))] pub use self::async_tls_adapter::client_async_tls_with_connector_and_config; -#[cfg(all(feature = "async-tls", not(any(feature = "tokio-native-tls", feature = "tokio-openssl"))))] +#[cfg(all( + feature = "async-tls", + not(any( + feature = "tokio-rustls", + feature = "tokio-native-tls", + feature = "tokio-openssl" + )) +))] use self::async_tls_adapter::{AutoStream, Connector}; -#[cfg(feature = "tokio-native-tls")] -use self::tokio_tls::{client_async_tls_with_connector_and_config, AutoStream, Connector}; - -#[cfg(feature = "tokio-rustls")] -pub use self::tokio_tls::client_async_tls_with_connector_and_config; -#[cfg(feature = "tokio-rustls")] -use self::tokio_tls::{AutoStream, Connector}; - -#[cfg(feature = "tokio-openssl")] +#[cfg(any( + feature = "tokio-rustls", + feature = "tokio-native-tls", + feature = "tokio-openssl" +))] pub use self::tokio_tls::client_async_tls_with_connector_and_config; -#[cfg(feature = "tokio-openssl")] +#[cfg(any( + feature = "tokio-rustls", + feature = "tokio-native-tls", + feature = "tokio-openssl" +))] use self::tokio_tls::{AutoStream, Connector}; /// Creates a WebSocket handshake from a request and a stream. @@ -528,7 +553,7 @@ where client_async_tls_with_connector_and_config(request, stream, connector, None).await } -#[cfg(feature = "tokio-openssl")] +#[cfg(all(feature = "tokio-openssl", not(feature = "tokio-native-tls")))] /// Creates a WebSocket handshake from a request and a stream, /// upgrading the stream to TLS if required. pub async fn client_async_tls( @@ -549,7 +574,7 @@ where client_async_tls_with_connector_and_config(request, stream, None, None).await } -#[cfg(feature = "tokio-openssl")] +#[cfg(all(feature = "tokio-openssl", not(feature = "tokio-native-tls")))] /// Creates a WebSocket handshake from a request and a stream, /// upgrading the stream to TLS if required and using the given /// WebSocket configuration. @@ -572,7 +597,7 @@ where client_async_tls_with_connector_and_config(request, stream, None, config).await } -#[cfg(feature = "tokio-openssl")] +#[cfg(all(feature = "tokio-openssl", not(feature = "tokio-native-tls")))] /// Creates a WebSocket handshake from a request and a stream, /// upgrading the stream to TLS if required and using the given /// connector.