@@ -10,7 +10,7 @@ use std::fmt;
10
10
use postgres:: { IntoConnectParams , SslMode } ;
11
11
12
12
/// A unified enum of errors returned by postgres::Connection
13
- #[ derive( Clone , Debug ) ]
13
+ #[ derive( Debug ) ]
14
14
pub enum Error {
15
15
/// A postgres::ConnectError
16
16
Connect ( postgres:: ConnectError ) ,
@@ -59,7 +59,7 @@ impl error::Error for Error {
59
59
/// fn main() {
60
60
/// let config = Default::default();
61
61
/// let manager = PostgresConnectionManager::new("postgres://postgres@localhost",
62
- /// SslMode::None);
62
+ /// SslMode::None).unwrap() ;
63
63
/// let error_handler = Box::new(r2d2::LoggingErrorHandler);
64
64
/// let pool = Arc::new(r2d2::Pool::new(config, manager, error_handler).unwrap());
65
65
///
@@ -73,7 +73,7 @@ impl error::Error for Error {
73
73
/// }
74
74
/// ```
75
75
pub struct PostgresConnectionManager {
76
- params : Result < postgres:: ConnectParams , postgres :: ConnectError > ,
76
+ params : postgres:: ConnectParams ,
77
77
ssl_mode : SslMode ,
78
78
}
79
79
@@ -89,11 +89,12 @@ impl PostgresConnectionManager {
89
89
///
90
90
/// See `postgres::Connection::connect` for a description of the parameter
91
91
/// types.
92
- pub fn new < T : IntoConnectParams > ( params : T , ssl_mode : SslMode ) ->PostgresConnectionManager {
93
- PostgresConnectionManager {
94
- params : params. into_connect_params ( ) ,
92
+ pub fn new < T : IntoConnectParams > ( params : T , ssl_mode : SslMode )
93
+ ->Result < PostgresConnectionManager , postgres:: ConnectError > {
94
+ Ok ( PostgresConnectionManager {
95
+ params : try!( params. into_connect_params ( ) ) ,
95
96
ssl_mode : ssl_mode,
96
- }
97
+ } )
97
98
}
98
99
}
99
100
@@ -102,12 +103,7 @@ impl r2d2::ConnectionManager for PostgresConnectionManager {
102
103
type Error =Error ;
103
104
104
105
fn connect ( & self ) ->Result < postgres:: Connection , Error > {
105
- match self . params {
106
- Ok ( ref p) =>{
107
- postgres:: Connection :: connect ( p. clone ( ) , & self . ssl_mode ) . map_err ( Error :: Connect )
108
- }
109
- Err ( ref e) =>Err ( Error :: Connect ( e. clone ( ) ) )
110
- }
106
+ postgres:: Connection :: connect ( self . params . clone ( ) , & self . ssl_mode ) . map_err ( Error :: Connect )
111
107
}
112
108
113
109
fn is_valid ( & self , conn : & mut postgres:: Connection ) ->Result < ( ) , Error > {