@@ -35,16 +35,12 @@ pub struct Error {
3535}
3636
3737impl Error {
38- pub ( crate ) fn new ( e : Arc < ErrorKind > ) -> Error {
39- Error {
40- kind : e,
41- labels : Vec :: new ( ) ,
42- }
43- }
44-
4538 pub ( crate ) fn pool_cleared_error ( address : & StreamAddress ) -> Self {
4639 ErrorKind :: ConnectionPoolClearedError {
47- message : format ! ( "Conneciton pool for {} cleared during operation execution" , address)
40+ message : format ! (
41+ "Connection pool for {} cleared during operation execution" ,
42+ address
43+ ) ,
4844 }
4945 . into ( )
5046 }
@@ -68,20 +64,6 @@ impl Error {
6864 Error :: authentication_error ( mechanism_name, "invalid server response" )
6965 }
7066
71- /// Attempts to get the `std::io::Error` from this `Error`.
72- /// If there are other references to the underlying `Arc`, or if the `ErrorKind` is not `Io`,
73- /// then the original error is returned as a custom `std::io::Error`.
74- pub ( crate ) fn into_io_error ( self ) -> std:: io:: Error {
75- match Arc :: try_unwrap ( self . kind ) {
76- Ok ( ErrorKind :: Io ( io_error) ) => io_error,
77- Ok ( other_error_kind) => {
78- let error: Error = other_error_kind. into ( ) ;
79- std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , Box :: new ( error) )
80- }
81- Err ( e) => std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , Box :: new ( Error :: new ( e) ) ) ,
82- }
83- }
84-
8567 /// Whether this error is an "ns not found" error or not.
8668 pub ( crate ) fn is_ns_not_found ( & self ) -> bool {
8769 matches ! ( self . kind. as_ref( ) , ErrorKind :: CommandError ( err) if err. code == 26 )
@@ -129,10 +111,13 @@ impl Error {
129111
130112 /// Whether an error originated from the server.
131113 pub ( crate ) fn is_server_error ( & self ) -> bool {
132- matches ! ( self . kind. as_ref( ) , ErrorKind :: AuthenticationError { .. }
133- | ErrorKind :: BulkWriteError ( _)
134- | ErrorKind :: CommandError ( _)
135- | ErrorKind :: WriteError ( _) )
114+ matches ! (
115+ self . kind. as_ref( ) ,
116+ ErrorKind :: AuthenticationError { .. }
117+ | ErrorKind :: BulkWriteError ( _)
118+ | ErrorKind :: CommandError ( _)
119+ | ErrorKind :: WriteError ( _)
120+ )
136121 }
137122
138123 /// Returns the labels for this error.
@@ -153,7 +138,9 @@ impl Error {
153138
154139 /// Whether this error contains the specified label.
155140 pub fn contains_label < T : AsRef < str > > ( & self , label : T ) -> bool {
156- self . labels ( ) . iter ( ) . any ( |actual_label| actual_label. as_str ( ) == label. as_ref ( ) )
141+ self . labels ( )
142+ . iter ( )
143+ . any ( |actual_label| actual_label. as_str ( ) == label. as_ref ( ) )
157144 }
158145
159146 /// Returns a copy of this Error with the specified label added.
@@ -334,7 +321,7 @@ pub enum ErrorKind {
334321 /// A timeout occurred before a Tokio task could be completed.
335322 #[ cfg( feature = "tokio-runtime" ) ]
336323 #[ error( display = "{}" , _0) ]
337- TokioTimeoutElapsed ( #[ error( source) ] tokio:: time:: Elapsed ) ,
324+ TokioTimeoutElapsed ( #[ error( source) ] tokio:: time:: error :: Elapsed ) ,
338325
339326 #[ error( display = "{}" , _0) ]
340327 RustlsConfig ( #[ error( source) ] rustls:: TLSError ) ,
@@ -372,7 +359,10 @@ impl ErrorKind {
372359 }
373360
374361 pub ( crate ) fn is_network_error ( & self ) -> bool {
375- matches ! ( self , ErrorKind :: Io ( ..) | ErrorKind :: ConnectionPoolClearedError { .. } )
362+ matches ! (
363+ self ,
364+ ErrorKind :: Io ( ..) | ErrorKind :: ConnectionPoolClearedError { .. }
365+ )
376366 }
377367
378368 /// Gets the code/message tuple from this error, if applicable. In the case of write errors, the
@@ -396,13 +386,14 @@ impl ErrorKind {
396386 pub ( crate ) fn code_name ( & self ) -> Option < & str > {
397387 match self {
398388 ErrorKind :: CommandError ( ref cmd_err) => Some ( cmd_err. code_name . as_str ( ) ) ,
399- ErrorKind :: WriteError ( ref failure) => {
400- match failure {
401- WriteFailure :: WriteConcernError ( ref wce) => Some ( wce. code_name . as_str ( ) ) ,
402- WriteFailure :: WriteError ( ref we) => we. code_name . as_deref ( ) ,
403- }
404- }
405- ErrorKind :: BulkWriteError ( ref bwe) => bwe. write_concern_error . as_ref ( ) . map ( |wce| wce. code_name . as_str ( ) ) ,
389+ ErrorKind :: WriteError ( ref failure) => match failure {
390+ WriteFailure :: WriteConcernError ( ref wce) => Some ( wce. code_name . as_str ( ) ) ,
391+ WriteFailure :: WriteError ( ref we) => we. code_name . as_deref ( ) ,
392+ } ,
393+ ErrorKind :: BulkWriteError ( ref bwe) => bwe
394+ . write_concern_error
395+ . as_ref ( )
396+ . map ( |wce| wce. code_name . as_str ( ) ) ,
406397 _ => None ,
407398 }
408399 }
0 commit comments