Skip to content

Commit 49c22a8

Browse files
committed
Add postgres examples to TLS crates
1 parent aaaf824 commit 49c22a8

File tree

4 files changed

+57
-10
lines changed

4 files changed

+57
-10
lines changed

tokio-postgres-native-tls/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ tokio-postgres = { version = "0.4.0-rc.1", path = "../tokio-postgres", default-f
2424

2525
[dev-dependencies]
2626
tokio = "0.1.7"
27+
postgres = { version = "0.1.0", path = "../postgres" }

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

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
//! TLS support for `tokio-postgres` via `native-tls.
1+
//! TLS support for `tokio-postgres` and `postgres` via `native-tls.
22
//!
3-
//! # Example
3+
//! # Examples
44
//!
55
//! ```no_run
66
//! use native_tls::{Certificate, TlsConnector};
77
//! use tokio_postgres_native_tls::MakeTlsConnector;
88
//! use std::fs;
99
//!
10-
//! let cert = fs::read("database_cert.pem").unwrap();
11-
//! let cert = Certificate::from_pem(&cert).unwrap();
10+
//! # fn main() -> Result<(), Box<std::error::Error>> {
11+
//! let cert = fs::read("database_cert.pem")?;
12+
//! let cert = Certificate::from_pem(&cert)?;
1213
//! let connector = TlsConnector::builder()
1314
//! .add_root_certificate(cert)
14-
//! .build()
15-
//! .unwrap();
15+
//! .build()?;
1616
//! let connector = MakeTlsConnector::new(connector);
1717
//!
1818
//! let connect_future = tokio_postgres::connect(
@@ -21,6 +21,29 @@
2121
//! );
2222
//!
2323
//! // ...
24+
//! # Ok(())
25+
//! # }
26+
//! ```
27+
//!
28+
//! ```no_run
29+
//! use native_tls::{Certificate, TlsConnector};
30+
//! use tokio_postgres_native_tls::MakeTlsConnector;
31+
//! use std::fs;
32+
//!
33+
//! # fn main() -> Result<(), Box<std::error::Error>> {
34+
//! let cert = fs::read("database_cert.pem")?;
35+
//! let cert = Certificate::from_pem(&cert)?;
36+
//! let connector = TlsConnector::builder()
37+
//! .add_root_certificate(cert)
38+
//! .build()?;
39+
//! let connector = MakeTlsConnector::new(connector);
40+
//!
41+
//! let mut client = postgres::Client::connect(
42+
//! "host=localhost user=postgres sslmode=require",
43+
//! connector,
44+
//! )?;
45+
//! # Ok(())
46+
//! # }
2447
//! ```
2548
#![doc(html_root_url = "https://docs.rs/tokio-postgres-native-tls/0.1.0-rc.1")]
2649
#![warn(rust_2018_idioms, clippy::all, missing_docs)]

tokio-postgres-openssl/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ tokio-postgres = { version = "0.4.0-rc.1", path = "../tokio-postgres", default-f
2424

2525
[dev-dependencies]
2626
tokio = "0.1.7"
27+
postgres = { version = "0.1", path = "../postgres" }

tokio-postgres-openssl/src/lib.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
//! TLS support for `tokio-postgres` via `openssl`.
1+
//! TLS support for `tokio-postgres` and `postgres` via `openssl`.
22
//!
3-
//! # Example
3+
//! # Examples
44
//!
55
//! ```no_run
66
//! use openssl::ssl::{SslConnector, SslMethod};
77
//! use tokio_postgres_openssl::MakeTlsConnector;
88
//!
9-
//! let mut builder = SslConnector::builder(SslMethod::tls()).unwrap();
10-
//! builder.set_ca_file("database_cert.pem").unwrap();
9+
//! # fn main() -> Result<(), Box<std::error::Error>> {
10+
//! let mut builder = SslConnector::builder(SslMethod::tls())?;
11+
//! builder.set_ca_file("database_cert.pem")?;
1112
//! let connector = MakeTlsConnector::new(builder.build());
1213
//!
1314
//! let connect_future = tokio_postgres::connect(
@@ -16,6 +17,27 @@
1617
//! );
1718
//!
1819
//! // ...
20+
//! # Ok(())
21+
//! # }
22+
//! ```
23+
//!
24+
//! ```no_run
25+
//! use openssl::ssl::{SslConnector, SslMethod};
26+
//! use tokio_postgres_openssl::MakeTlsConnector;
27+
//!
28+
//! # fn main() -> Result<(), Box<std::error::Error>> {
29+
//! let mut builder = SslConnector::builder(SslMethod::tls())?;
30+
//! builder.set_ca_file("database_cert.pem")?;
31+
//! let connector = MakeTlsConnector::new(builder.build());
32+
//!
33+
//! let mut client = postgres::Client::connect(
34+
//! "host=localhost user=postgres sslmode=require",
35+
//! connector,
36+
//! )?;
37+
//!
38+
//! // ...
39+
//! # Ok(())
40+
//! # }
1941
//! ```
2042
#![doc(html_root_url = "https://docs.rs/tokio-postgres-openssl/0.1.0-rc.1")]
2143
#![warn(rust_2018_idioms, clippy::all, missing_docs)]

0 commit comments

Comments
 (0)