@@ -32,7 +32,7 @@ impl Error {
3232}
3333
3434/// The different categories of errors that can be returned when reading from raw BSON.
35- #[ derive( Clone , Debug , PartialEq ) ]
35+ #[ derive( Clone , Debug ) ]
3636#[ non_exhaustive]
3737pub enum ErrorKind {
3838 /// A BSON value did not fit the proper format.
@@ -41,6 +41,24 @@ pub enum ErrorKind {
4141
4242 /// Improper UTF-8 bytes were found when proper UTF-8 was expected.
4343 Utf8EncodingError ,
44+
45+ /// A wrapped deserialization error.
46+ /// TODO RUST-1406: collapse this
47+ DeError ( crate :: de:: Error ) ,
48+ }
49+
50+ impl PartialEq for ErrorKind {
51+ fn eq ( & self , other : & Self ) -> bool {
52+ match ( self , other) {
53+ (
54+ Self :: MalformedValue { message : l_message } ,
55+ Self :: MalformedValue { message : r_message } ,
56+ ) => l_message == r_message,
57+ ( Self :: Utf8EncodingError , Self :: Utf8EncodingError ) => true ,
58+ ( Self :: DeError ( _) , Self :: DeError ( _) ) => true ,
59+ _ => false ,
60+ }
61+ }
4462}
4563
4664impl std:: fmt:: Display for Error {
@@ -57,10 +75,17 @@ impl std::fmt::Display for Error {
5775 write ! ( f, "{}malformed value: {:?}" , prefix, message)
5876 }
5977 ErrorKind :: Utf8EncodingError => write ! ( f, "{}utf-8 encoding error" , prefix) ,
78+ ErrorKind :: DeError ( e) => write ! ( f, "{}deserialization error: {}" , prefix, e) ,
6079 }
6180 }
6281}
6382
83+ impl From < crate :: de:: Error > for Error {
84+ fn from ( value : crate :: de:: Error ) -> Self {
85+ Self :: new ( ErrorKind :: DeError ( value) )
86+ }
87+ }
88+
6489impl std:: error:: Error for Error { }
6590
6691pub type Result < T > = std:: result:: Result < T , Error > ;
0 commit comments