|
1 | | -//! TLS support for `tokio-postgres` via `native-tls. |
| 1 | +//! TLS support for `tokio-postgres` and `postgres` via `native-tls. |
2 | 2 | //! |
3 | | -//! # Example |
| 3 | +//! # Examples |
4 | 4 | //! |
5 | 5 | //! ```no_run |
6 | 6 | //! use native_tls::{Certificate, TlsConnector}; |
7 | 7 | //! use tokio_postgres_native_tls::MakeTlsConnector; |
8 | 8 | //! use std::fs; |
9 | 9 | //! |
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)?; |
12 | 13 | //! let connector = TlsConnector::builder() |
13 | 14 | //! .add_root_certificate(cert) |
14 | | -//! .build() |
15 | | -//! .unwrap(); |
| 15 | +//! .build()?; |
16 | 16 | //! let connector = MakeTlsConnector::new(connector); |
17 | 17 | //! |
18 | 18 | //! let connect_future = tokio_postgres::connect( |
|
21 | 21 | //! ); |
22 | 22 | //! |
23 | 23 | //! // ... |
| 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 | +//! # } |
24 | 47 | //! ``` |
25 | 48 | #![doc(html_root_url = "https://docs.rs/tokio-postgres-native-tls/0.1.0-rc.1")] |
26 | 49 | #![warn(rust_2018_idioms, clippy::all, missing_docs)] |
|
0 commit comments