99use std:: collections:: { hash_map, HashMap , VecDeque } ;
1010use std:: sync:: { Arc , Mutex } ;
1111
12- #[ cfg( all( feature = "rustls" , feature = "tokio-rustls" ) ) ]
12+ #[ cfg( any(
13+ all( feature = "native-tls" , feature = "tokio-native-tls" ) ,
14+ all( feature = "rustls" , feature = "tokio-rustls" )
15+ ) ) ]
1316use crate :: connection:: certificates:: { Certificates , CertificatesBuilder } ;
1417use crate :: connection:: AsyncConnection ;
1518use crate :: request:: { OwnedConnectionParams as ConnectionKey , ParsedRequest } ;
1619use crate :: { Error , Request , Response } ;
1720
1821#[ derive( Clone ) ]
1922pub ( crate ) struct ClientConfig {
20- #[ cfg( all( feature = "rustls" , feature = "tokio-rustls" ) ) ]
23+ #[ cfg( any(
24+ all( feature = "native-tls" , feature = "tokio-native-tls" ) ,
25+ all( feature = "rustls" , feature = "tokio-rustls" )
26+ ) ) ]
2127 pub ( crate ) tls : Option < TlsConfig > ,
2228}
2329
24- #[ cfg( all( feature = "rustls" , feature = "tokio-rustls" ) ) ]
30+ #[ cfg( any(
31+ all( feature = "native-tls" , feature = "tokio-native-tls" ) ,
32+ all( feature = "rustls" , feature = "tokio-rustls" )
33+ ) ) ]
2534#[ derive( Clone ) ]
2635pub ( crate ) struct TlsConfig {
2736 pub ( crate ) certificates : Certificates ,
2837}
2938
30- #[ cfg( all( feature = "rustls" , feature = "tokio-rustls" ) ) ]
39+ #[ cfg( any(
40+ all( feature = "native-tls" , feature = "tokio-native-tls" ) ,
41+ all( feature = "rustls" , feature = "tokio-rustls" )
42+ ) ) ]
3143impl TlsConfig {
3244 fn new ( certificates : Certificates ) -> Self { Self { certificates } }
3345}
3446
3547pub struct ClientBuilder {
3648 capacity : usize ,
37- #[ cfg( all( feature = "rustls" , feature = "tokio-rustls" ) ) ]
49+ #[ cfg( any(
50+ all( feature = "native-tls" , feature = "tokio-native-tls" ) ,
51+ all( feature = "rustls" , feature = "tokio-rustls" )
52+ ) ) ]
3853 certificates : Option < CertificatesBuilder > ,
3954}
4055
@@ -56,11 +71,17 @@ pub struct ClientBuilder {
5671/// ```
5772impl ClientBuilder {
5873 /// Creates a new `ClientBuilder` with a default pool capacity of 10.
59- #[ cfg( all( feature = "rustls" , feature = "tokio-rustls" ) ) ]
74+ #[ cfg( any(
75+ all( feature = "native-tls" , feature = "tokio-native-tls" ) ,
76+ all( feature = "rustls" , feature = "tokio-rustls" )
77+ ) ) ]
6078 pub fn new ( ) -> Self { Self { capacity : 10 , certificates : None } }
6179
6280 /// Creates a new `ClientBuilder` with a default pool capacity of 10.
63- #[ cfg( not( all( feature = "rustls" , feature = "tokio-rustls" ) ) ) ]
81+ #[ cfg( not( any(
82+ all( feature = "native-tls" , feature = "tokio-native-tls" ) ,
83+ all( feature = "rustls" , feature = "tokio-rustls" )
84+ ) ) ) ]
6485 pub fn new ( ) -> Self { Self { capacity : 10 } }
6586
6687 /// Sets the maximum number of connections to keep in the pool.
@@ -69,7 +90,10 @@ impl ClientBuilder {
6990 self
7091 }
7192
72- #[ cfg( all( feature = "rustls" , feature = "tokio-rustls" ) ) ]
93+ #[ cfg( any(
94+ all( feature = "native-tls" , feature = "tokio-native-tls" ) ,
95+ all( feature = "rustls" , feature = "tokio-rustls" )
96+ ) ) ]
7397 /// Builds the `Client` with the configured settings.
7498 pub fn build ( self ) -> Result < Client , Error > {
7599 let build_config = if let Some ( builder) = self . certificates {
@@ -92,7 +116,10 @@ impl ClientBuilder {
92116 }
93117
94118 /// Builds the `Client` with the configured settings.
95- #[ cfg( not( any( all( feature = "rustls" , feature = "tokio-rustls" ) ) ) ) ]
119+ #[ cfg( not( any(
120+ all( feature = "native-tls" , feature = "tokio-native-tls" ) ,
121+ all( feature = "rustls" , feature = "tokio-rustls" )
122+ ) ) ) ]
96123 pub fn build ( self ) -> Result < Client , Error > {
97124 Ok ( Client {
98125 r#async : Arc :: new ( Mutex :: new ( ClientImpl {
@@ -122,7 +149,10 @@ impl ClientBuilder {
122149 /// # Ok(())
123150 /// # }
124151 /// ```
125- #[ cfg( all( feature = "rustls" , feature = "tokio-rustls" ) ) ]
152+ #[ cfg( any(
153+ all( feature = "native-tls" , feature = "tokio-native-tls" ) ,
154+ all( feature = "rustls" , feature = "tokio-rustls" )
155+ ) ) ]
126156 pub fn with_root_certificate < T : Into < Vec < u8 > > > ( mut self , cert_der : T ) -> Result < Self , Error > {
127157 let cert_der = cert_der. into ( ) ;
128158 if let Some ( ref mut certificates) = self . certificates {
@@ -137,7 +167,10 @@ impl ClientBuilder {
137167
138168 /// Disables default root certificates for TLS connections.
139169 /// Returns [`Error::InvalidTlsConfig`] if TLS has not been configured.
140- #[ cfg( all( feature = "rustls" , feature = "tokio-rustls" ) ) ]
170+ #[ cfg( any(
171+ all( feature = "native-tls" , feature = "tokio-native-tls" ) ,
172+ all( feature = "rustls" , feature = "tokio-rustls" )
173+ ) ) ]
141174 pub fn disable_default_certificates ( mut self ) -> Result < Self , Error > {
142175 match self . certificates {
143176 Some ( ref mut certificates) => certificates. disable_default ( ) ?,
0 commit comments