11//! Postgres support for the `r2d2` connection pool.
2- #![ doc( html_root_url="https://sfackler.github.io/r2d2-postgres/doc/v0.9.3 " ) ]
2+ #![ doc( html_root_url="https://sfackler.github.io/r2d2-postgres/doc/v0.10.0 " ) ]
33#![ warn( missing_docs) ]
44extern crate r2d2;
55extern crate postgres;
66
77use std:: error;
88use std:: error:: Error as _StdError;
99use std:: fmt;
10- use postgres:: { IntoConnectParams , SslMode } ;
10+ use postgres:: { IntoConnectParams } ;
11+ use postgres:: io:: NegotiateSsl ;
12+
13+ /// Like `postgres::SslMode` except that it owns its `NegotiateSsl` instance.
14+ #[ derive( Debug ) ]
15+ pub enum SslMode {
16+ /// Like `postgres::SslMode::None`.
17+ None ,
18+ /// Like `postgres::SslMode::Prefer`.
19+ Prefer ( Box < NegotiateSsl + Sync + Send > ) ,
20+ /// Like `postgres::SslMode::Require`.
21+ Require ( Box < NegotiateSsl + Sync + Send > ) ,
22+ }
1123
1224/// A unified enum of errors returned by postgres::Connection
1325#[ derive( Debug ) ]
@@ -45,22 +57,18 @@ impl error::Error for Error {
4557/// ## Example
4658///
4759/// ```rust,no_run
48- /// #![allow(unstable)]
4960/// extern crate r2d2;
5061/// extern crate r2d2_postgres;
5162/// extern crate postgres;
5263///
53- /// use std::sync::Arc;
54- /// use std::default::Default;
5564/// use std::thread;
56- /// use postgres::SslMode;
57- /// use r2d2_postgres::PostgresConnectionManager;
65+ /// use r2d2_postgres::{SslMode, PostgresConnectionManager};
5866///
5967/// fn main() {
6068/// let config = r2d2::Config::default();
6169/// let manager = PostgresConnectionManager::new("postgres://postgres@localhost",
6270/// SslMode::None).unwrap();
63- /// let pool = Arc::new( r2d2::Pool::new(config, manager).unwrap() );
71+ /// let pool = r2d2::Pool::new(config, manager).unwrap();
6472///
6573/// for i in 0..10i32 {
6674/// let pool = pool.clone();
@@ -86,7 +94,7 @@ impl PostgresConnectionManager {
8694 -> Result < PostgresConnectionManager , postgres:: error:: ConnectError > {
8795 let params = match params. into_connect_params ( ) {
8896 Ok ( params) => params,
89- Err ( err) => return Err ( postgres:: error:: ConnectError :: BadConnectParams ( err) ) ,
97+ Err ( err) => return Err ( postgres:: error:: ConnectError :: ConnectParams ( err) ) ,
9098 } ;
9199
92100 Ok ( PostgresConnectionManager {
@@ -101,7 +109,12 @@ impl r2d2::ManageConnection for PostgresConnectionManager {
101109 type Error = Error ;
102110
103111 fn connect ( & self ) -> Result < postgres:: Connection , Error > {
104- postgres:: Connection :: connect ( self . params . clone ( ) , & self . ssl_mode ) . map_err ( Error :: Connect )
112+ let mode = match self . ssl_mode {
113+ SslMode :: None => postgres:: SslMode :: None ,
114+ SslMode :: Prefer ( ref n) => postgres:: SslMode :: Prefer ( & * * n) ,
115+ SslMode :: Require ( ref n) => postgres:: SslMode :: Require ( & * * n) ,
116+ } ;
117+ postgres:: Connection :: connect ( self . params . clone ( ) , mode) . map_err ( Error :: Connect )
105118 }
106119
107120 fn is_valid ( & self , conn : & mut postgres:: Connection ) -> Result < ( ) , Error > {
0 commit comments