11//! Contains the `Error` and `Result` types that `mongodb` uses.
22
3- use std:: { fmt, sync:: Arc } ;
3+ use std:: { fmt:: { self , Debug } , sync:: Arc } ;
44
55use serde:: Deserialize ;
66use thiserror:: Error ;
@@ -27,7 +27,7 @@ pub type Result<T> = std::result::Result<T, Error>;
2727#[ non_exhaustive]
2828pub struct Error {
2929 /// The type of error that occurred.
30- pub kind : ErrorKind ,
30+ pub kind : Box < ErrorKind > ,
3131 labels : Vec < String > ,
3232}
3333
@@ -66,20 +66,20 @@ impl Error {
6666 }
6767
6868 pub ( crate ) fn is_auth_error ( & self ) -> bool {
69- matches ! ( self . kind, ErrorKind :: AuthenticationError { .. } )
69+ matches ! ( self . kind. as_ref ( ) , ErrorKind :: AuthenticationError { .. } )
7070 }
7171
7272 pub ( crate ) fn is_command_error ( & self ) -> bool {
73- matches ! ( self . kind, ErrorKind :: CommandError ( _) )
73+ matches ! ( self . kind. as_ref ( ) , ErrorKind :: CommandError ( _) )
7474 }
7575
7676 pub ( crate ) fn is_network_timeout ( & self ) -> bool {
77- matches ! ( self . kind, ErrorKind :: Io ( ref io_err) if io_err. kind( ) == std:: io:: ErrorKind :: TimedOut )
77+ matches ! ( self . kind. as_ref ( ) , ErrorKind :: Io ( ref io_err) if io_err. kind( ) == std:: io:: ErrorKind :: TimedOut )
7878 }
7979
8080 /// Whether this error is an "ns not found" error or not.
8181 pub ( crate ) fn is_ns_not_found ( & self ) -> bool {
82- matches ! ( self . kind, ErrorKind :: CommandError ( ref err) if err. code == 26 )
82+ matches ! ( self . kind. as_ref ( ) , ErrorKind :: CommandError ( ref err) if err. code == 26 )
8383 }
8484
8585 /// Whether a read operation should be retried if this error occurs.
@@ -119,7 +119,7 @@ impl Error {
119119 /// Whether an error originated from the server.
120120 pub ( crate ) fn is_server_error ( & self ) -> bool {
121121 matches ! (
122- self . kind,
122+ self . kind. as_ref ( ) ,
123123 ErrorKind :: AuthenticationError { .. }
124124 | ErrorKind :: BulkWriteError ( _)
125125 | ErrorKind :: CommandError ( _)
@@ -129,7 +129,7 @@ impl Error {
129129
130130 /// Returns the labels for this error.
131131 pub fn labels ( & self ) -> & [ String ] {
132- match self . kind {
132+ match self . kind . as_ref ( ) {
133133 ErrorKind :: CommandError ( ref err) => & err. labels ,
134134 ErrorKind :: WriteError ( ref err) => match err {
135135 WriteFailure :: WriteError ( _) => & self . labels ,
@@ -153,7 +153,7 @@ impl Error {
153153 /// Returns a copy of this Error with the specified label added.
154154 pub ( crate ) fn with_label < T : AsRef < str > > ( mut self , label : T ) -> Self {
155155 let label = label. as_ref ( ) . to_string ( ) ;
156- match self . kind {
156+ match self . kind . as_ref ( ) {
157157 ErrorKind :: CommandError ( ref err) => {
158158 let mut err = err. clone ( ) ;
159159 err. labels . push ( label) ;
@@ -197,7 +197,7 @@ where
197197{
198198 fn from ( err : E ) -> Self {
199199 Self {
200- kind : err. into ( ) ,
200+ kind : Box :: new ( err. into ( ) ) ,
201201 labels : Vec :: new ( ) ,
202202 }
203203 }
@@ -603,7 +603,7 @@ impl WriteFailure {
603603/// Translates ErrorKind::BulkWriteError cases to ErrorKind::WriteErrors, leaving all other errors
604604/// untouched.
605605pub ( crate ) fn convert_bulk_errors ( error : Error ) -> Error {
606- match error. kind {
606+ match * error. kind {
607607 ErrorKind :: BulkWriteError ( ref bulk_failure) => {
608608 match WriteFailure :: from_bulk_failure ( bulk_failure. clone ( ) ) {
609609 Ok ( failure) => ErrorKind :: WriteError ( failure) . into ( ) ,
0 commit comments