Skip to content

Commit 5262ed7

Browse files
committed
Simplify ConnectionManager impl
1 parent a5dbf60 commit 5262ed7

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

src/pool.rs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@
3333
//! use skytable::sync::{Connection, TlsConnection};
3434
//!
3535
//! // non-TLS (TCP pool)
36-
//! let notls_manager = ConnectionManager::<Connection>::new_notls("127.0.0.1".into(), 2003);
36+
//! let notls_manager = ConnectionManager::new_notls("127.0.0.1".into(), 2003);
3737
//! let notls_pool = Pool::builder()
3838
//! .max_size(10)
3939
//! .build(notls_manager)
4040
//! .unwrap();
4141
//!
4242
//! // TLS pool
43-
//! let tls_manager = ConnectionManager::<TlsConnection>::new_tls(
43+
//! let tls_manager = ConnectionManager::new_tls(
4444
//! "127.0.0.1".into(), 2003, "cert.pem".into()
4545
//! );
4646
//! let notls_pool = TlsPool::builder()
@@ -58,15 +58,15 @@
5858
//! use skytable::aio::{Connection, TlsConnection};
5959
//! async fn run() {
6060
//! // non-TLS (TCP pool)
61-
//! let notls_manager = ConnectionManager::<Connection>::new_notls("127.0.0.1".into(), 2003);
61+
//! let notls_manager = ConnectionManager::new_notls("127.0.0.1".into(), 2003);
6262
//! let notls_pool = AsyncPool::builder()
6363
//! .max_size(10)
6464
//! .build(notls_manager)
6565
//! .await
6666
//! .unwrap();
6767
//!
6868
//! // TLS pool
69-
//! let tls_manager = ConnectionManager::<TlsConnection>::new_tls(
69+
//! let tls_manager = ConnectionManager::new_tls(
7070
//! "127.0.0.1".into(), 2003, "cert.pem".into()
7171
//! );
7272
//! let notls_pool = AsyncTlsPool::builder()
@@ -114,6 +114,15 @@ impl<C> ConnectionManager<C> {
114114
}
115115
}
116116

117+
impl<C> ConnectionManager<C> {
118+
pub fn new_notls(host: String, port: u16) -> ConnectionManager<C> {
119+
Self::_new(host, port, None)
120+
}
121+
pub fn new_tls(host: String, port: u16, cert: String) -> ConnectionManager<C> {
122+
Self::_new(host, port, Some(cert))
123+
}
124+
}
125+
117126
#[cfg(any(feature = "sync", feature = "pool"))]
118127
mod sync_impls {
119128
use super::ConnectionManager;
@@ -127,17 +136,6 @@ mod sync_impls {
127136
pub type Pool = r2d2::Pool<ConnectionManager<SyncConnection>>;
128137
pub type TlsPool = r2d2::Pool<ConnectionManager<SyncTlsConnection>>;
129138

130-
impl ConnectionManager<SyncConnection> {
131-
pub fn new_notls(host: String, port: u16) -> Self {
132-
Self::_new(host, port, None)
133-
}
134-
}
135-
impl ConnectionManager<SyncTlsConnection> {
136-
pub fn new_tls(host: String, port: u16, cert: String) -> Self {
137-
Self::_new(host, port, Some(cert))
138-
}
139-
}
140-
141139
pub trait PoolableConnection: Send + Sync + Sized {
142140
fn get_connection(host: &str, port: u16, tls_cert: Option<&String>) -> SkyResult<Self>;
143141
fn run_query(&mut self, q: Query) -> SkyQueryResult;
@@ -248,17 +246,6 @@ mod async_impls {
248246
}
249247
}
250248

251-
impl ConnectionManager<AsyncConnection> {
252-
pub fn new_notls(host: String, port: u16) -> Self {
253-
Self::_new(host, port, None)
254-
}
255-
}
256-
impl ConnectionManager<AsyncTlsConnection> {
257-
pub fn new_tls(host: String, port: u16, cert: String) -> Self {
258-
Self::_new(host, port, Some(cert))
259-
}
260-
}
261-
262249
#[async_trait]
263250
impl<C: PoolableConnection + 'static> ManageConnection for ConnectionManager<C> {
264251
type Connection = C;

0 commit comments

Comments
 (0)