@@ -97,6 +97,8 @@ pub use bb8::RunError as bb8Error;
9797use core:: marker:: PhantomData ;
9898
9999#[ derive( Debug , Clone ) ]
100+ /// A [`ConnectionManager`] for connection pools. See the [module level documentation](crate::pool)
101+ /// for examples and more information
100102pub struct ConnectionManager < C > {
101103 host : String ,
102104 port : u16 ,
@@ -116,9 +118,11 @@ impl<C> ConnectionManager<C> {
116118}
117119
118120impl < C > ConnectionManager < C > {
121+ /// Create a new `ConnectionManager` that can be used to configure a non-TLS connection pool
119122 pub fn new_notls ( host : String , port : u16 ) -> ConnectionManager < C > {
120123 Self :: _new ( host, port, None )
121124 }
125+ /// Create a new `ConnectionManager` that can be used to configure a TLS connection pool
122126 pub fn new_tls ( host : String , port : u16 , cert : String ) -> ConnectionManager < C > {
123127 Self :: _new ( host, port, Some ( cert) )
124128 }
@@ -127,15 +131,22 @@ impl<C> ConnectionManager<C> {
127131#[ cfg( any( feature = "sync" , feature = "pool" ) ) ]
128132mod sync_impls {
129133 use super :: ConnectionManager ;
130- use crate :: sync:: { Connection as SyncConnection , TlsConnection as SyncTlsConnection } ;
134+ use crate :: sync:: Connection as SyncConnection ;
135+ cfg_sync_ssl_any ! {
136+ use crate :: sync:: TlsConnection as SyncTlsConnection ;
137+ }
131138 use crate :: {
132139 error:: { Error , SkyhashError } ,
133140 Element , Query , SkyQueryResult , SkyResult ,
134141 } ;
135142 use r2d2:: ManageConnection ;
136143
144+ /// A non-TLS connection pool to Skytable
137145 pub type Pool = r2d2:: Pool < ConnectionManager < SyncConnection > > ;
138- pub type TlsPool = r2d2:: Pool < ConnectionManager < SyncTlsConnection > > ;
146+ cfg_sync_ssl_any ! {
147+ /// A TLS connection pool to Skytable
148+ pub type TlsPool = r2d2:: Pool <ConnectionManager <SyncTlsConnection >>;
149+ }
139150
140151 pub trait PoolableConnection : Send + Sync + Sized {
141152 fn get_connection ( host : & str , port : u16 , tls_cert : Option < & String > ) -> SkyResult < Self > ;
@@ -152,19 +163,21 @@ mod sync_impls {
152163 }
153164 }
154165
155- impl PoolableConnection for SyncTlsConnection {
156- fn get_connection ( host : & str , port : u16 , tls_cert : Option < & String > ) -> SkyResult < Self > {
157- let c = Self :: new (
158- & host,
159- port,
160- tls_cert. ok_or ( Error :: ConfigurationError (
161- "Expected TLS certificate in `ConnectionManager`" ,
162- ) ) ?,
163- ) ?;
164- Ok ( c)
165- }
166- fn run_query ( & mut self , q : Query ) -> SkyQueryResult {
167- self . run_simple_query ( & q)
166+ cfg_sync_ssl_any ! {
167+ impl PoolableConnection for SyncTlsConnection {
168+ fn get_connection( host: & str , port: u16 , tls_cert: Option <& String >) -> SkyResult <Self > {
169+ let c = Self :: new(
170+ & host,
171+ port,
172+ tls_cert. ok_or( Error :: ConfigurationError (
173+ "Expected TLS certificate in `ConnectionManager`" ,
174+ ) ) ?,
175+ ) ?;
176+ Ok ( c)
177+ }
178+ fn run_query( & mut self , q: Query ) -> SkyQueryResult {
179+ self . run_simple_query( & q)
180+ }
168181 }
169182 }
170183 impl < C : PoolableConnection + ' static > ManageConnection for ConnectionManager < C > {
@@ -189,17 +202,23 @@ mod sync_impls {
189202#[ cfg( any( feature = "aio" , feature = "aio-pool" ) ) ]
190203mod async_impls {
191204 use super :: ConnectionManager ;
192- use crate :: aio:: { Connection as AsyncConnection , TlsConnection as AsyncTlsConnection } ;
205+ use crate :: aio:: Connection as AsyncConnection ;
206+ cfg_async_ssl_any ! {
207+ use crate :: aio:: TlsConnection as AsyncTlsConnection ;
208+ }
193209 use crate :: {
194210 error:: { Error , SkyhashError } ,
195211 Element , Query , SkyQueryResult , SkyResult ,
196212 } ;
197213 use async_trait:: async_trait;
198214 use bb8:: { ManageConnection , PooledConnection } ;
199215
216+ /// An asynchronous non-TLS connection pool to Skytable
200217 pub type Pool = bb8:: Pool < ConnectionManager < AsyncConnection > > ;
201- pub type TlsPool = bb8:: Pool < ConnectionManager < AsyncTlsConnection > > ;
202-
218+ cfg_async_ssl_any ! {
219+ /// An asynchronous TLS connection pool to Skytable
220+ pub type TlsPool = bb8:: Pool <ConnectionManager <AsyncTlsConnection >>;
221+ }
203222 #[ async_trait]
204223 pub trait PoolableConnection : Send + Sync + Sized {
205224 async fn get_connection (
@@ -225,25 +244,27 @@ mod async_impls {
225244 }
226245 }
227246
228- #[ async_trait]
229- impl PoolableConnection for AsyncTlsConnection {
230- async fn get_connection (
231- host : & str ,
232- port : u16 ,
233- tls_cert : Option < & String > ,
234- ) -> SkyResult < Self > {
235- let con = AsyncTlsConnection :: new (
236- & host,
237- port,
238- tls_cert. ok_or ( Error :: ConfigurationError (
239- "Expected TLS certificate in `ConnectionManager`" ,
240- ) ) ?,
241- )
242- . await ?;
243- Ok ( con)
244- }
245- async fn run_query ( & mut self , q : Query ) -> SkyQueryResult {
246- self . run_simple_query ( & q) . await
247+ cfg_async_ssl_any ! {
248+ #[ async_trait]
249+ impl PoolableConnection for AsyncTlsConnection {
250+ async fn get_connection(
251+ host: & str ,
252+ port: u16 ,
253+ tls_cert: Option <& String >,
254+ ) -> SkyResult <Self > {
255+ let con = AsyncTlsConnection :: new(
256+ & host,
257+ port,
258+ tls_cert. ok_or( Error :: ConfigurationError (
259+ "Expected TLS certificate in `ConnectionManager`" ,
260+ ) ) ?,
261+ )
262+ . await ?;
263+ Ok ( con)
264+ }
265+ async fn run_query( & mut self , q: Query ) -> SkyQueryResult {
266+ self . run_simple_query( & q) . await
267+ }
247268 }
248269 }
249270
0 commit comments