Skip to content

Commit eb1722f

Browse files
committed
Fix SSL feature flag errors and update docs
1 parent f0d7f94 commit eb1722f

File tree

3 files changed

+78
-39
lines changed

3 files changed

+78
-39
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ This library is the official client for the free and open-source NoSQL database
77
following the instructions [here](https://docs.skytable.io/getting-started). This library supports
88
all Skytable versions that work with the [Skyhash 1.1 Protocol](https://docs.skytable.io/protocol/skyhash).
99
This version of the library was tested with the latest Skytable release
10-
(release [0.7.2-alpha.1](https://github.com/skytable/skytable/releases/v0.7.2-alpha.1)).
10+
(release [0.7.2](https://github.com/skytable/skytable/releases/v0.7.2)).
11+
12+
## Features
13+
14+
- Sync API
15+
- Async API
16+
- TLS in both sync/async APIs
17+
- Connection pooling for sync/async
18+
- Use both sync/async APIs at the same time
19+
- Always up-to-date
1120

1221
## Using this library
1322

src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@
2424
//! This version of the library was tested with the latest Skytable release
2525
//! (release [0.7](https://github.com/skytable/skytable/releases/v0.7.0)).
2626
//!
27-
//! ## Using this library
27+
//! ## Features
28+
//!
29+
//! - Sync API
30+
//! - Async API
31+
//! - TLS in both sync/async APIs
32+
//! - Connection pooling for sync/async
33+
//! - Use both sync/async APIs at the same time
34+
//! - Always up-to-date
35+
//!
36+
//! ## Using this library
2837
//!
2938
//! This library only ships with the bare minimum that is required for interacting with Skytable. Once you have
3039
//! Skytable installed and running, you're ready to follow this guide!

src/pool.rs

Lines changed: 58 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ pub use bb8::RunError as bb8Error;
9797
use 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
100102
pub struct ConnectionManager<C> {
101103
host: String,
102104
port: u16,
@@ -116,9 +118,11 @@ impl<C> ConnectionManager<C> {
116118
}
117119

118120
impl<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"))]
128132
mod 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"))]
190203
mod 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

Comments
 (0)