Skip to content

Commit e12902a

Browse files
committed
Document tokio-postgres-native-tls
1 parent 374fadb commit e12902a

File tree

1 file changed

+33
-1
lines changed
  • tokio-postgres-native-tls/src

1 file changed

+33
-1
lines changed

tokio-postgres-native-tls/src/lib.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
1-
#![warn(rust_2018_idioms, clippy::all)]
1+
//! TLS support for `tokio-postgres` via `native-tls.
2+
//!
3+
//! # Example
4+
//!
5+
//! ```no_run
6+
//! use native_tls::{Certificate, TlsConnector};
7+
//! use tokio_postgres_native_tls::MakeTlsConnector;
8+
//! use std::fs;
9+
//!
10+
//! let cert = fs::read("database_cert.pem").unwrap();
11+
//! let cert = Certificate::from_pem(&cert).unwrap();
12+
//! let connector = TlsConnector::builder()
13+
//! .add_root_certificate(cert)
14+
//! .build()
15+
//! .unwrap();
16+
//! let connector = MakeTlsConnector::new(connector);
17+
//!
18+
//! let connect_future = tokio_postgres::connect(
19+
//! "host=localhost user=postgres sslmode=require",
20+
//! connector,
21+
//! );
22+
//!
23+
//! // ...
24+
//! ```
25+
26+
#![warn(rust_2018_idioms, clippy::all, missing_docs)]
227

328
use futures::{try_ready, Async, Future, Poll};
429
use tokio_io::{AsyncRead, AsyncWrite};
@@ -10,12 +35,16 @@ use tokio_tls::{Connect, TlsStream};
1035
#[cfg(test)]
1136
mod test;
1237

38+
/// A `MakeTlsConnect` implementation using the `native-tls` crate.
39+
///
40+
/// Requires the `runtime` Cargo feature (enabled by default).
1341
#[cfg(feature = "runtime")]
1442
#[derive(Clone)]
1543
pub struct MakeTlsConnector(native_tls::TlsConnector);
1644

1745
#[cfg(feature = "runtime")]
1846
impl MakeTlsConnector {
47+
/// Creates a new connector.
1948
pub fn new(connector: native_tls::TlsConnector) -> MakeTlsConnector {
2049
MakeTlsConnector(connector)
2150
}
@@ -35,12 +64,14 @@ where
3564
}
3665
}
3766

67+
/// A `TlsConnect` implementation using the `native-tls` crate.
3868
pub struct TlsConnector {
3969
connector: tokio_tls::TlsConnector,
4070
domain: String,
4171
}
4272

4373
impl TlsConnector {
74+
/// Creates a new connector configured to connect to the specified domain.
4475
pub fn new(connector: native_tls::TlsConnector, domain: &str) -> TlsConnector {
4576
TlsConnector {
4677
connector: tokio_tls::TlsConnector::from(connector),
@@ -62,6 +93,7 @@ where
6293
}
6394
}
6495

96+
/// The future returned by `TlsConnector`.
6597
pub struct TlsConnectFuture<S>(Connect<S>);
6698

6799
impl<S> Future for TlsConnectFuture<S>

0 commit comments

Comments
 (0)