@@ -36,7 +36,7 @@ impl Error {
3636}
3737
3838/// The different categories of errors that can be returned when reading from raw BSON.
39- #[ derive( Clone , Debug , PartialEq ) ]
39+ #[ derive( Clone , Debug ) ]
4040#[ non_exhaustive]
4141pub enum ErrorKind {
4242 /// A BSON value did not fit the proper format.
@@ -45,6 +45,24 @@ pub enum ErrorKind {
4545
4646 /// Improper UTF-8 bytes were found when proper UTF-8 was expected.
4747 Utf8EncodingError ( Utf8Error ) ,
48+
49+ /// A wrapped deserialization error.
50+ /// TODO RUST-1406: collapse this
51+ DeError ( crate :: de:: Error ) ,
52+ }
53+
54+ impl PartialEq for ErrorKind {
55+ fn eq ( & self , other : & Self ) -> bool {
56+ match ( self , other) {
57+ (
58+ Self :: MalformedValue { message : l_message } ,
59+ Self :: MalformedValue { message : r_message } ,
60+ ) => l_message == r_message,
61+ ( Self :: Utf8EncodingError ( l0) , Self :: Utf8EncodingError ( r0) ) => l0 == r0,
62+ ( Self :: DeError ( _) , Self :: DeError ( _) ) => true ,
63+ _ => false ,
64+ }
65+ }
4866}
4967
5068impl std:: fmt:: Display for Error {
@@ -61,10 +79,17 @@ impl std::fmt::Display for Error {
6179 write ! ( f, "{}malformed value: {:?}" , prefix, message)
6280 }
6381 ErrorKind :: Utf8EncodingError ( e) => write ! ( f, "{}utf-8 encoding error: {}" , prefix, e) ,
82+ ErrorKind :: DeError ( e) => write ! ( f, "{}deserialization error: {}" , prefix, e) ,
6483 }
6584 }
6685}
6786
87+ impl From < crate :: de:: Error > for Error {
88+ fn from ( value : crate :: de:: Error ) -> Self {
89+ Self :: new ( ErrorKind :: DeError ( value) )
90+ }
91+ }
92+
6893impl std:: error:: Error for Error { }
6994
7095pub type Result < T > = std:: result:: Result < T , Error > ;
0 commit comments