|
38 | 38 | //! }
|
39 | 39 | //! }
|
40 | 40 | //! ```
|
| 41 | +//! |
| 42 | +//! # SSL/TLS |
| 43 | +//! |
| 44 | +//! This crate supports TLS secured connections. The `TlsMode` enum is passed to connection methods |
| 45 | +//! and indicates if the connection will not, may not, or must be secured by TLS. The TLS |
| 46 | +//! implementation is pluggable through the `TlsHandshake` trait. Implementations for OpenSSL and |
| 47 | +//! OSX's Secure Transport are provided behing the `with-openssl` and `with-security-framework` |
| 48 | +//! feature flags respectively. |
| 49 | +//! |
| 50 | +//! ## Examples |
| 51 | +//! |
| 52 | +//! Connecting using OpenSSL: |
| 53 | +//! |
| 54 | +//! ```no_run |
| 55 | +//! extern crate postgres; |
| 56 | +//! |
| 57 | +//! use postgres::{Connection, TlsMode}; |
| 58 | +//! # #[cfg(feature = "with-openssl")] |
| 59 | +//! use postgres::io::openssl::OpenSsl; |
| 60 | +//! |
| 61 | +//! # #[cfg(not(feature = "with-openssl"))] fn main() {} |
| 62 | +//! # #[cfg(feature = "with-openssl")] |
| 63 | +//! fn main() { |
| 64 | +//! let openssl = OpenSsl::new().unwrap(); |
| 65 | +//! // Configure the `SslContext` with the `.context()` and `.context_mut()` methods |
| 66 | +//! |
| 67 | +//! let conn = Connection::connect("postgres://postgres@localhost", TlsMode::Require(&openssl)) |
| 68 | +//! .unwrap(); |
| 69 | +//! } |
| 70 | +//! ``` |
41 | 71 | #![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.11.11")]
|
42 | 72 | #![warn(missing_docs)]
|
43 | 73 | #![allow(unknown_lints, needless_lifetimes, doc_markdown)] // for clippy
|
@@ -878,20 +908,23 @@ impl Connection {
|
878 | 908 | ///
|
879 | 909 | /// # Examples
|
880 | 910 | ///
|
| 911 | + /// To connect over TCP: |
881 | 912 | /// ```rust,no_run
|
882 | 913 | /// use postgres::{Connection, TlsMode};
|
883 | 914 | ///
|
884 | 915 | /// let url = "postgresql://postgres:hunter2@localhost:2994/foodb";
|
885 | 916 | /// let conn = Connection::connect(url, TlsMode::None).unwrap();
|
886 | 917 | /// ```
|
887 | 918 | ///
|
| 919 | + /// To connect over a Unix socket located in `/run/postgres`: |
888 | 920 | /// ```rust,no_run
|
889 | 921 | /// use postgres::{Connection, TlsMode};
|
890 | 922 | ///
|
891 | 923 | /// let url = "postgresql://postgres@%2Frun%2Fpostgres";
|
892 | 924 | /// let conn = Connection::connect(url, TlsMode::None).unwrap();
|
893 | 925 | /// ```
|
894 | 926 | ///
|
| 927 | + /// To connect building a `ConnectParams` struct manually: |
895 | 928 | /// ```rust,no_run
|
896 | 929 | /// use postgres::{Connection, TlsMode};
|
897 | 930 | /// use postgres::params::{UserInfo, ConnectParams, ConnectTarget};
|
|
0 commit comments