@@ -10,7 +10,7 @@ use std::fmt;
1010use postgres:: { IntoConnectParams , SslMode } ;
1111
1212/// A unified enum of errors returned by postgres::Connection
13- #[ derive( Clone , Debug ) ]
13+ #[ derive( Debug ) ]
1414pub enum Error {
1515 /// A postgres::ConnectError
1616 Connect ( postgres:: ConnectError ) ,
@@ -59,7 +59,7 @@ impl error::Error for Error {
5959/// fn main() {
6060/// let config = Default::default();
6161/// let manager = PostgresConnectionManager::new("postgres://postgres@localhost",
62- /// SslMode::None);
62+ /// SslMode::None).unwrap() ;
6363/// let error_handler = Box::new(r2d2::LoggingErrorHandler);
6464/// let pool = Arc::new(r2d2::Pool::new(config, manager, error_handler).unwrap());
6565///
@@ -73,7 +73,7 @@ impl error::Error for Error {
7373/// }
7474/// ```
7575pub struct PostgresConnectionManager {
76- params : Result < postgres:: ConnectParams , postgres :: ConnectError > ,
76+ params : postgres:: ConnectParams ,
7777 ssl_mode : SslMode ,
7878}
7979
@@ -89,11 +89,12 @@ impl PostgresConnectionManager {
8989 ///
9090 /// See `postgres::Connection::connect` for a description of the parameter
9191 /// 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 ( ) ) ,
9596 ssl_mode : ssl_mode,
96- }
97+ } )
9798 }
9899}
99100
@@ -102,12 +103,7 @@ impl r2d2::ConnectionManager for PostgresConnectionManager {
102103 type Error = Error ;
103104
104105 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 )
111107 }
112108
113109 fn is_valid ( & self , conn : & mut postgres:: Connection ) -> Result < ( ) , Error > {
0 commit comments