@@ -61,10 +61,12 @@ use std::ascii::AsciiExt;
61
61
use std:: borrow:: ToOwned ;
62
62
use std:: cell:: { Cell , RefCell } ;
63
63
use std:: collections:: { VecDeque , HashMap } ;
64
+ use std:: error:: Error as StdError ;
64
65
use std:: fmt;
65
66
use std:: iter:: IntoIterator ;
66
67
use std:: io as std_io;
67
68
use std:: io:: prelude:: * ;
69
+ use std:: marker:: Sync as StdSync ;
68
70
use std:: mem;
69
71
use std:: result;
70
72
#[ cfg( feature = "unix_socket" ) ]
@@ -145,26 +147,26 @@ pub struct ConnectParams {
145
147
/// A trait implemented by types that can be converted into a `ConnectParams`.
146
148
pub trait IntoConnectParams {
147
149
/// Converts the value of `self` into a `ConnectParams`.
148
- fn into_connect_params ( self ) -> result:: Result < ConnectParams , ConnectError > ;
150
+ fn into_connect_params ( self ) -> result:: Result < ConnectParams , Box < StdError + StdSync + Send > > ;
149
151
}
150
152
151
153
impl IntoConnectParams for ConnectParams {
152
- fn into_connect_params ( self ) -> result:: Result < ConnectParams , ConnectError > {
154
+ fn into_connect_params ( self ) -> result:: Result < ConnectParams , Box < StdError + StdSync + Send > > {
153
155
Ok ( self )
154
156
}
155
157
}
156
158
157
159
impl < ' a > IntoConnectParams for & ' a str {
158
- fn into_connect_params ( self ) -> result:: Result < ConnectParams , ConnectError > {
160
+ fn into_connect_params ( self ) -> result:: Result < ConnectParams , Box < StdError + StdSync + Send > > {
159
161
match Url :: parse ( self ) {
160
162
Ok ( url) => url. into_connect_params ( ) ,
161
- Err ( err) => return Err ( ConnectError :: InvalidUrl ( err) ) ,
163
+ Err ( err) => return Err ( err. into ( ) ) ,
162
164
}
163
165
}
164
166
}
165
167
166
168
impl IntoConnectParams for Url {
167
- fn into_connect_params ( self ) -> result:: Result < ConnectParams , ConnectError > {
169
+ fn into_connect_params ( self ) -> result:: Result < ConnectParams , Box < StdError + StdSync + Send > > {
168
170
let Url {
169
171
host,
170
172
port,
@@ -174,16 +176,16 @@ impl IntoConnectParams for Url {
174
176
} = self ;
175
177
176
178
#[ cfg( feature = "unix_socket" ) ]
177
- fn make_unix ( maybe_path : String ) -> result:: Result < ConnectTarget , ConnectError > {
179
+ fn make_unix ( maybe_path : String )
180
+ -> result:: Result < ConnectTarget , Box < StdError +StdSync +Send > > {
178
181
Ok ( ConnectTarget :: Unix ( PathBuf :: from ( maybe_path) ) )
179
182
}
180
183
#[ cfg( not( feature = "unix_socket" ) ) ]
181
- fn make_unix ( _: String ) -> result:: Result < ConnectTarget , ConnectError > {
182
- Err ( ConnectError :: InvalidUrl ( "unix socket support requires the `unix_socket` feature"
183
- . to_string ( ) ) )
184
+ fn make_unix ( _: String ) -> result:: Result < ConnectTarget , Box < StdError +StdSync +Send > > {
185
+ Err ( "unix socket support requires the `unix_socket` feature" . into ( ) )
184
186
}
185
187
186
- let maybe_path = try!( url:: decode_component ( & host) . map_err ( ConnectError :: InvalidUrl ) ) ;
188
+ let maybe_path = try!( url:: decode_component ( & host) ) ;
187
189
let target = if maybe_path. starts_with ( "/" ) {
188
190
try!( make_unix ( maybe_path) )
189
191
} else {
@@ -330,7 +332,7 @@ pub struct CancelData {
330
332
pub fn cancel_query < T > ( params : T , ssl : & SslMode , data : CancelData )
331
333
-> result:: Result < ( ) , ConnectError >
332
334
where T : IntoConnectParams {
333
- let params = try!( params. into_connect_params ( ) ) ;
335
+ let params = try!( params. into_connect_params ( ) . map_err ( ConnectError :: BadConnectParams ) ) ;
334
336
let mut socket = try!( priv_io:: initialize_stream ( & params, ssl) ) ;
335
337
336
338
try!( socket. write_message ( & CancelRequest {
@@ -459,7 +461,7 @@ impl Drop for InnerConnection {
459
461
impl InnerConnection {
460
462
fn connect < T > ( params : T , ssl : & SslMode ) -> result:: Result < InnerConnection , ConnectError >
461
463
where T : IntoConnectParams {
462
- let params = try!( params. into_connect_params ( ) ) ;
464
+ let params = try!( params. into_connect_params ( ) . map_err ( ConnectError :: BadConnectParams ) ) ;
463
465
let stream = try!( priv_io:: initialize_stream ( & params, ssl) ) ;
464
466
465
467
let ConnectParams { user, database, mut options, .. } = params;
0 commit comments