@@ -2,21 +2,47 @@ use chrono::{DateTime, UTC};
2
2
use bson:: { Array , Bson , Document } ;
3
3
use super :: oid:: ObjectId ;
4
4
use std:: collections:: BTreeMap ;
5
- use std:: fmt:: { Display , Error , Formatter } ;
5
+ use std:: error;
6
+ use std:: fmt;
7
+ use std:: fmt:: { Debug , Display , Error , Formatter } ;
6
8
use std:: iter:: { FromIterator , Map } ;
7
9
use std:: vec:: IntoIter ;
8
10
use std:: slice;
9
11
10
12
/// Error to indicate that either a value was empty or it contained an unexpected
11
13
/// type, for use with the direct getters.
12
- #[ derive( Debug , PartialEq ) ]
14
+ #[ derive( PartialEq ) ]
13
15
pub enum ValueAccessError {
14
16
NotPresent ,
15
17
UnexpectedType
16
18
}
17
19
18
20
pub type ValueAccessResult < T > = Result < T , ValueAccessError > ;
19
21
22
+ impl Debug for ValueAccessError {
23
+ fn fmt ( & self , f : & mut Formatter ) -> fmt:: Result {
24
+ match * self {
25
+ ValueAccessError :: NotPresent => write ! ( f, "ValueAccessError: field is not present" ) ,
26
+ ValueAccessError :: UnexpectedType => write ! ( f, "ValueAccessError: field does not have the expected type" )
27
+ }
28
+ }
29
+ }
30
+
31
+ impl Display for ValueAccessError {
32
+ fn fmt ( & self , f : & mut Formatter ) -> fmt:: Result {
33
+ match * self {
34
+ ValueAccessError :: NotPresent => write ! ( f, "field is not present" ) ,
35
+ ValueAccessError :: UnexpectedType => write ! ( f, "field does not have the expected type" )
36
+ }
37
+ }
38
+ }
39
+
40
+ impl error:: Error for ValueAccessError {
41
+ fn description ( & self ) -> & str {
42
+ "Error to indicate that either a value was empty or it contained an unexpected type"
43
+ }
44
+ }
45
+
20
46
/// A BSON document represented as an associative BTree Map with insertion ordering.
21
47
#[ derive( Debug , Clone , PartialEq ) ]
22
48
pub struct OrderedDocument {
0 commit comments