@@ -28,7 +28,7 @@ pub type Result<T> = std::result::Result<T, Error>;
28
28
#[ non_exhaustive]
29
29
pub struct Error {
30
30
/// The type of error that occurred.
31
- pub kind : Arc < ErrorKind > ,
31
+ pub kind : ErrorKind ,
32
32
labels : Vec < String > ,
33
33
}
34
34
@@ -64,7 +64,7 @@ impl Error {
64
64
65
65
/// Whether this error is an "ns not found" error or not.
66
66
pub ( crate ) fn is_ns_not_found ( & self ) -> bool {
67
- matches ! ( self . kind. as_ref ( ) , ErrorKind :: CommandError ( err) if err. code == 26 )
67
+ matches ! ( self . kind, ErrorKind :: CommandError ( ref err) if err. code == 26 )
68
68
}
69
69
70
70
/// Whether a read operation should be retried if this error occurs.
@@ -110,7 +110,7 @@ impl Error {
110
110
/// Whether an error originated from the server.
111
111
pub ( crate ) fn is_server_error ( & self ) -> bool {
112
112
matches ! (
113
- self . kind. as_ref ( ) ,
113
+ self . kind,
114
114
ErrorKind :: AuthenticationError { .. }
115
115
| ErrorKind :: BulkWriteError ( _)
116
116
| ErrorKind :: CommandError ( _)
@@ -120,13 +120,13 @@ impl Error {
120
120
121
121
/// Returns the labels for this error.
122
122
pub fn labels ( & self ) -> & [ String ] {
123
- match self . kind . as_ref ( ) {
124
- ErrorKind :: CommandError ( err) => & err. labels ,
125
- ErrorKind :: WriteError ( err) => match err {
123
+ match self . kind {
124
+ ErrorKind :: CommandError ( ref err) => & err. labels ,
125
+ ErrorKind :: WriteError ( ref err) => match err {
126
126
WriteFailure :: WriteError ( _) => & self . labels ,
127
- WriteFailure :: WriteConcernError ( err) => & err. labels ,
127
+ WriteFailure :: WriteConcernError ( ref err) => & err. labels ,
128
128
} ,
129
- ErrorKind :: BulkWriteError ( err) => match err. write_concern_error {
129
+ ErrorKind :: BulkWriteError ( ref err) => match err. write_concern_error {
130
130
Some ( ref err) => & err. labels ,
131
131
None => & self . labels ,
132
132
} ,
@@ -144,24 +144,24 @@ impl Error {
144
144
/// Returns a copy of this Error with the specified label added.
145
145
pub ( crate ) fn with_label < T : AsRef < str > > ( mut self , label : T ) -> Self {
146
146
let label = label. as_ref ( ) . to_string ( ) ;
147
- match self . kind . as_ref ( ) {
148
- ErrorKind :: CommandError ( err) => {
147
+ match self . kind {
148
+ ErrorKind :: CommandError ( ref err) => {
149
149
let mut err = err. clone ( ) ;
150
150
err. labels . push ( label) ;
151
151
ErrorKind :: CommandError ( err) . into ( )
152
152
}
153
- ErrorKind :: WriteError ( err) => match err {
153
+ ErrorKind :: WriteError ( ref err) => match err {
154
154
WriteFailure :: WriteError ( _) => {
155
155
self . labels . push ( label) ;
156
156
self
157
157
}
158
- WriteFailure :: WriteConcernError ( err) => {
158
+ WriteFailure :: WriteConcernError ( ref err) => {
159
159
let mut err = err. clone ( ) ;
160
160
err. labels . push ( label) ;
161
161
ErrorKind :: WriteError ( WriteFailure :: WriteConcernError ( err) ) . into ( )
162
162
}
163
163
} ,
164
- ErrorKind :: BulkWriteError ( err) => match err. write_concern_error {
164
+ ErrorKind :: BulkWriteError ( ref err) => match err. write_concern_error {
165
165
Some ( ref write_concern_error) => {
166
166
let mut err = err. clone ( ) ;
167
167
let mut write_concern_error = write_concern_error. clone ( ) ;
@@ -188,14 +188,38 @@ where
188
188
{
189
189
fn from ( err : E ) -> Self {
190
190
Self {
191
- kind : Arc :: new ( err. into ( ) ) ,
191
+ kind : err. into ( ) ,
192
192
labels : Vec :: new ( ) ,
193
193
}
194
194
}
195
195
}
196
196
197
+ impl From < bson:: de:: Error > for ErrorKind {
198
+ fn from ( err : bson:: de:: Error ) -> Self {
199
+ Self :: BsonDecode ( Arc :: new ( err) )
200
+ }
201
+ }
202
+
203
+ impl From < bson:: ser:: Error > for ErrorKind {
204
+ fn from ( err : bson:: ser:: Error ) -> Self {
205
+ Self :: BsonEncode ( Arc :: new ( err) )
206
+ }
207
+ }
208
+
209
+ impl From < std:: io:: Error > for ErrorKind {
210
+ fn from ( err : std:: io:: Error ) -> Self {
211
+ Self :: Io ( Arc :: new ( err) )
212
+ }
213
+ }
214
+
215
+ impl From < std:: io:: ErrorKind > for ErrorKind {
216
+ fn from ( err : std:: io:: ErrorKind ) -> Self {
217
+ Self :: Io ( Arc :: new ( err. into ( ) ) )
218
+ }
219
+ }
220
+
197
221
impl std:: ops:: Deref for Error {
198
- type Target = Arc < ErrorKind > ;
222
+ type Target = ErrorKind ;
199
223
200
224
fn deref ( & self ) -> & Self :: Target {
201
225
& self . kind
@@ -204,7 +228,7 @@ impl std::ops::Deref for Error {
204
228
205
229
/// The types of errors that can occur.
206
230
#[ allow( missing_docs) ]
207
- #[ derive( Debug , Error ) ]
231
+ #[ derive( Clone , Debug , Error ) ]
208
232
#[ non_exhaustive]
209
233
pub enum ErrorKind {
210
234
/// Wrapper around [`std::net::AddrParseError`](https://doc.rust-lang.org/std/net/struct.AddrParseError.html).
@@ -216,10 +240,6 @@ pub enum ErrorKind {
216
240
#[ non_exhaustive]
217
241
ArgumentError { message : String } ,
218
242
219
- #[ cfg( feature = "async-std-runtime" ) ]
220
- #[ error( "{0}" ) ]
221
- AsyncStdTimeout ( #[ from] async_std:: future:: TimeoutError ) ,
222
-
223
243
/// An error occurred while the [`Client`](../struct.Client.html) attempted to authenticate a
224
244
/// connection.
225
245
#[ error( "{message}" ) ]
@@ -228,11 +248,11 @@ pub enum ErrorKind {
228
248
229
249
/// Wrapper around `bson::de::Error`.
230
250
#[ error( "{0}" ) ]
231
- BsonDecode ( # [ from ] crate :: bson:: de:: Error ) ,
251
+ BsonDecode ( Arc < crate :: bson:: de:: Error > ) ,
232
252
233
253
/// Wrapper around `bson::ser::Error`.
234
254
#[ error( "{0}" ) ]
235
- BsonEncode ( # [ from ] crate :: bson:: ser:: Error ) ,
255
+ BsonEncode ( Arc < crate :: bson:: ser:: Error > ) ,
236
256
237
257
/// An error occurred when trying to execute a write operation consisting of multiple writes.
238
258
#[ error( "An error occurred when trying to execute a write operation: {0:?}" ) ]
@@ -263,7 +283,7 @@ pub enum ErrorKind {
263
283
264
284
/// Wrapper around [`std::io::Error`](https://doc.rust-lang.org/std/io/struct.Error.html).
265
285
#[ error( "{0}" ) ]
266
- Io ( # [ from ] std:: io:: Error ) ,
286
+ Io ( Arc < std:: io:: Error > ) ,
267
287
268
288
#[ error( "No DNS results for domain {0}" ) ]
269
289
NoDnsResults ( StreamAddress ) ,
@@ -305,11 +325,6 @@ pub enum ErrorKind {
305
325
#[ non_exhaustive]
306
326
SrvLookupError { message : String } ,
307
327
308
- /// A timeout occurred before a Tokio task could be completed.
309
- #[ cfg( feature = "tokio-runtime" ) ]
310
- #[ error( "{0}" ) ]
311
- TokioTimeoutElapsed ( #[ from] tokio:: time:: error:: Elapsed ) ,
312
-
313
328
#[ error( "{0}" ) ]
314
329
RustlsConfig ( #[ from] rustls:: TLSError ) ,
315
330
@@ -565,7 +580,7 @@ impl WriteFailure {
565
580
/// Translates ErrorKind::BulkWriteError cases to ErrorKind::WriteErrors, leaving all other errors
566
581
/// untouched.
567
582
pub ( crate ) fn convert_bulk_errors ( error : Error ) -> Error {
568
- match * error. kind {
583
+ match error. kind {
569
584
ErrorKind :: BulkWriteError ( ref bulk_failure) => {
570
585
match WriteFailure :: from_bulk_failure ( bulk_failure. clone ( ) ) {
571
586
Ok ( failure) => ErrorKind :: WriteError ( failure) . into ( ) ,
0 commit comments