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