11//! Postgres support for the `r2d2` connection pool.
2- #![ doc( html_root_url="https://sfackler.github.io/r2d2-postgres/doc/v0.10.1 " ) ]
2+ #![ doc( html_root_url="https://sfackler.github.io/r2d2-postgres/doc/v0.11.0 " ) ]
33#![ warn( missing_docs) ]
4- extern crate r2d2;
5- extern crate postgres;
4+ pub extern crate r2d2;
5+ pub extern crate postgres;
66
77use std:: error;
88use std:: error:: Error as _StdError;
99use std:: fmt;
10- use postgres:: IntoConnectParams ;
11- use postgres:: io :: NegotiateSsl ;
10+ use postgres:: params :: { ConnectParams , IntoConnectParams } ;
11+ use postgres:: tls :: TlsHandshake ;
1212
13- /// Like `postgres::SslMode ` except that it owns its `NegotiateSsl ` instance.
13+ /// Like `postgres::TlsMode ` except that it owns its `TlsHandshake ` instance.
1414#[ derive( Debug ) ]
15- pub enum SslMode {
16- /// Like `postgres::SslMode ::None`.
15+ pub enum TlsMode {
16+ /// Like `postgres::TlsMode ::None`.
1717 None ,
18- /// Like `postgres::SslMode ::Prefer`.
19- Prefer ( Box < NegotiateSsl + Sync + Send > ) ,
20- /// Like `postgres::SslMode ::Require`.
21- Require ( Box < NegotiateSsl + Sync + Send > ) ,
18+ /// Like `postgres::TlsMode ::Prefer`.
19+ Prefer ( Box < TlsHandshake + Sync + Send > ) ,
20+ /// Like `postgres::TlsMode ::Require`.
21+ Require ( Box < TlsHandshake + Sync + Send > ) ,
2222}
2323
2424/// A unified enum of errors returned by postgres::Connection
@@ -62,12 +62,12 @@ impl error::Error for Error {
6262/// extern crate postgres;
6363///
6464/// use std::thread;
65- /// use r2d2_postgres::{SslMode , PostgresConnectionManager};
65+ /// use r2d2_postgres::{TlsMode , PostgresConnectionManager};
6666///
6767/// fn main() {
6868/// let config = r2d2::Config::default();
6969/// let manager = PostgresConnectionManager::new("postgres://postgres@localhost",
70- /// SslMode ::None).unwrap();
70+ /// TlsMode ::None).unwrap();
7171/// let pool = r2d2::Pool::new(config, manager).unwrap();
7272///
7373/// for i in 0..10i32 {
@@ -81,19 +81,20 @@ impl error::Error for Error {
8181/// ```
8282#[ derive( Debug ) ]
8383pub struct PostgresConnectionManager {
84- params : postgres :: ConnectParams ,
85- ssl_mode : SslMode ,
84+ params : ConnectParams ,
85+ ssl_mode : TlsMode ,
8686}
8787
8888impl PostgresConnectionManager {
8989 /// Creates a new `PostgresConnectionManager`.
9090 ///
9191 /// See `postgres::Connection::connect` for a description of the parameter
9292 /// types.
93- pub fn new < T : IntoConnectParams >
94- ( params : T ,
95- ssl_mode : SslMode )
96- -> Result < PostgresConnectionManager , postgres:: error:: ConnectError > {
93+ pub fn new < T > ( params : T ,
94+ ssl_mode : TlsMode )
95+ -> Result < PostgresConnectionManager , postgres:: error:: ConnectError >
96+ where T : IntoConnectParams
97+ {
9798 let params = match params. into_connect_params ( ) {
9899 Ok ( params) => params,
99100 Err ( err) => return Err ( postgres:: error:: ConnectError :: ConnectParams ( err) ) ,
@@ -112,9 +113,9 @@ impl r2d2::ManageConnection for PostgresConnectionManager {
112113
113114 fn connect ( & self ) -> Result < postgres:: Connection , Error > {
114115 let mode = match self . ssl_mode {
115- SslMode :: None => postgres:: SslMode :: None ,
116- SslMode :: Prefer ( ref n) => postgres:: SslMode :: Prefer ( & * * n) ,
117- SslMode :: Require ( ref n) => postgres:: SslMode :: Require ( & * * n) ,
116+ TlsMode :: None => postgres:: TlsMode :: None ,
117+ TlsMode :: Prefer ( ref n) => postgres:: TlsMode :: Prefer ( & * * n) ,
118+ TlsMode :: Require ( ref n) => postgres:: TlsMode :: Require ( & * * n) ,
118119 } ;
119120 postgres:: Connection :: connect ( self . params . clone ( ) , mode) . map_err ( Error :: Connect )
120121 }
0 commit comments