@@ -7,7 +7,19 @@ extern crate postgres;
7
7
use std:: error;
8
8
use std:: error:: Error as _StdError;
9
9
use 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
+ }
11
23
12
24
/// A unified enum of errors returned by postgres::Connection
13
25
#[ derive( Debug ) ]
@@ -45,14 +57,12 @@ impl error::Error for Error {
45
57
/// ## Example
46
58
///
47
59
/// ```rust,no_run
48
- /// #![allow(unstable)]
49
60
/// extern crate r2d2;
50
61
/// extern crate r2d2_postgres;
51
62
/// extern crate postgres;
52
63
///
53
64
/// use std::thread;
54
- /// use postgres::SslMode;
55
- /// use r2d2_postgres::PostgresConnectionManager;
65
+ /// use r2d2_postgres::{SslMode, PostgresConnectionManager};
56
66
///
57
67
/// fn main() {
58
68
/// let config = r2d2::Config::default();
@@ -84,7 +94,7 @@ impl PostgresConnectionManager {
84
94
->Result < PostgresConnectionManager , postgres:: error:: ConnectError > {
85
95
let params =match params. into_connect_params ( ) {
86
96
Ok ( params) => params,
87
- Err ( err) =>return Err ( postgres:: error:: ConnectError :: BadConnectParams ( err) ) ,
97
+ Err ( err) =>return Err ( postgres:: error:: ConnectError :: ConnectParams ( err) ) ,
88
98
} ;
89
99
90
100
Ok ( PostgresConnectionManager {
@@ -99,7 +109,12 @@ impl r2d2::ManageConnection for PostgresConnectionManager {
99
109
type Error =Error ;
100
110
101
111
fn connect ( & self ) ->Result < postgres:: Connection , Error > {
102
- 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 )
103
118
}
104
119
105
120
fn is_valid ( & self , conn : & mut postgres:: Connection ) ->Result < ( ) , Error > {