@@ -34,7 +34,7 @@ impl Error {
3434}
3535
3636/// The different categories of errors that can be returned when reading from raw BSON.
37- #[ derive( Clone , Debug , PartialEq ) ]
37+ #[ derive( Clone , Debug ) ]
3838#[ non_exhaustive]
3939pub enum ErrorKind {
4040 /// A BSON value did not fit the proper format.
@@ -43,6 +43,24 @@ pub enum ErrorKind {
4343
4444 /// Improper UTF-8 bytes were found when proper UTF-8 was expected.
4545 Utf8EncodingError ,
46+
47+ /// A wrapped deserialization error.
48+ /// TODO RUST-1406: collapse this
49+ DeError ( crate :: de:: Error ) ,
50+ }
51+
52+ impl PartialEq for ErrorKind {
53+ fn eq ( & self , other : & Self ) -> bool {
54+ match ( self , other) {
55+ (
56+ Self :: MalformedValue { message : l_message } ,
57+ Self :: MalformedValue { message : r_message } ,
58+ ) => l_message == r_message,
59+ ( Self :: Utf8EncodingError , Self :: Utf8EncodingError ) => true ,
60+ ( Self :: DeError ( _) , Self :: DeError ( _) ) => true ,
61+ _ => false ,
62+ }
63+ }
4664}
4765
4866impl std:: fmt:: Display for Error {
@@ -59,10 +77,17 @@ impl std::fmt::Display for Error {
5977 write ! ( f, "{}malformed value: {:?}" , prefix, message)
6078 }
6179 ErrorKind :: Utf8EncodingError => write ! ( f, "{}utf-8 encoding error" , prefix) ,
80+ ErrorKind :: DeError ( e) => write ! ( f, "{}deserialization error: {}" , prefix, e) ,
6281 }
6382 }
6483}
6584
85+ impl From < crate :: de:: Error > for Error {
86+ fn from ( value : crate :: de:: Error ) -> Self {
87+ Self :: new ( ErrorKind :: DeError ( value) )
88+ }
89+ }
90+
6691impl std:: error:: Error for Error { }
6792
6893pub type Result < T > = std:: result:: Result < T , Error > ;
0 commit comments