@@ -3,133 +3,7 @@ use error::*;
3
3
use serde:: de;
4
4
use std:: collections:: { HashMap , VecDeque } ;
5
5
use std:: iter:: Enumerate ;
6
- use value:: { Value , ValueKind , ValueWithKey , Table } ;
7
-
8
- // TODO: Use a macro or some other magic to reduce the code duplication here
9
-
10
- impl < ' de > de:: Deserializer < ' de > for ValueWithKey < ' de > {
11
- type Error = ConfigError ;
12
-
13
- #[ inline]
14
- fn deserialize_any < V > ( self , visitor : V ) -> Result < V :: Value >
15
- where
16
- V : de:: Visitor < ' de > ,
17
- {
18
- // Deserialize based on the underlying type
19
- match self . 0 . kind {
20
- ValueKind :: Nil => visitor. visit_unit ( ) ,
21
- ValueKind :: Integer ( i) => visitor. visit_i64 ( i) ,
22
- ValueKind :: Boolean ( b) => visitor. visit_bool ( b) ,
23
- ValueKind :: Float ( f) => visitor. visit_f64 ( f) ,
24
- ValueKind :: String ( s) => visitor. visit_string ( s) ,
25
- ValueKind :: Array ( values) => visitor. visit_seq ( SeqAccess :: new ( values) ) ,
26
- ValueKind :: Table ( map) => visitor. visit_map ( MapAccess :: new ( map) ) ,
27
- }
28
- }
29
-
30
- #[ inline]
31
- fn deserialize_bool < V : de:: Visitor < ' de > > ( self , visitor : V ) -> Result < V :: Value > {
32
- visitor. visit_bool ( self . into_bool ( ) ?)
33
- }
34
-
35
- #[ inline]
36
- fn deserialize_i8 < V : de:: Visitor < ' de > > ( self , visitor : V ) -> Result < V :: Value > {
37
- // FIXME: This should *fail* if the value does not fit in the requets integer type
38
- visitor. visit_i8 ( self . into_int ( ) ? as i8 )
39
- }
40
-
41
- #[ inline]
42
- fn deserialize_i16 < V : de:: Visitor < ' de > > ( self , visitor : V ) -> Result < V :: Value > {
43
- // FIXME: This should *fail* if the value does not fit in the requets integer type
44
- visitor. visit_i16 ( self . into_int ( ) ? as i16 )
45
- }
46
-
47
- #[ inline]
48
- fn deserialize_i32 < V : de:: Visitor < ' de > > ( self , visitor : V ) -> Result < V :: Value > {
49
- // FIXME: This should *fail* if the value does not fit in the requets integer type
50
- visitor. visit_i32 ( self . into_int ( ) ? as i32 )
51
- }
52
-
53
- #[ inline]
54
- fn deserialize_i64 < V : de:: Visitor < ' de > > ( self , visitor : V ) -> Result < V :: Value > {
55
- visitor. visit_i64 ( self . into_int ( ) ?)
56
- }
57
-
58
- #[ inline]
59
- fn deserialize_u8 < V : de:: Visitor < ' de > > ( self , visitor : V ) -> Result < V :: Value > {
60
- // FIXME: This should *fail* if the value does not fit in the requets integer type
61
- visitor. visit_u8 ( self . into_int ( ) ? as u8 )
62
- }
63
-
64
- #[ inline]
65
- fn deserialize_u16 < V : de:: Visitor < ' de > > ( self , visitor : V ) -> Result < V :: Value > {
66
- // FIXME: This should *fail* if the value does not fit in the requets integer type
67
- visitor. visit_u16 ( self . into_int ( ) ? as u16 )
68
- }
69
-
70
- #[ inline]
71
- fn deserialize_u32 < V : de:: Visitor < ' de > > ( self , visitor : V ) -> Result < V :: Value > {
72
- // FIXME: This should *fail* if the value does not fit in the requets integer type
73
- visitor. visit_u32 ( self . into_int ( ) ? as u32 )
74
- }
75
-
76
- #[ inline]
77
- fn deserialize_u64 < V : de:: Visitor < ' de > > ( self , visitor : V ) -> Result < V :: Value > {
78
- // FIXME: This should *fail* if the value does not fit in the requets integer type
79
- visitor. visit_u64 ( self . into_int ( ) ? as u64 )
80
- }
81
-
82
- #[ inline]
83
- fn deserialize_f32 < V : de:: Visitor < ' de > > ( self , visitor : V ) -> Result < V :: Value > {
84
- visitor. visit_f32 ( self . into_float ( ) ? as f32 )
85
- }
86
-
87
- #[ inline]
88
- fn deserialize_f64 < V : de:: Visitor < ' de > > ( self , visitor : V ) -> Result < V :: Value > {
89
- visitor. visit_f64 ( self . into_float ( ) ?)
90
- }
91
-
92
- #[ inline]
93
- fn deserialize_str < V : de:: Visitor < ' de > > ( self , visitor : V ) -> Result < V :: Value > {
94
- visitor. visit_string ( self . into_str ( ) ?)
95
- }
96
-
97
- #[ inline]
98
- fn deserialize_string < V : de:: Visitor < ' de > > ( self , visitor : V ) -> Result < V :: Value > {
99
- visitor. visit_string ( self . into_str ( ) ?)
100
- }
101
-
102
- #[ inline]
103
- fn deserialize_option < V > ( self , visitor : V ) -> Result < V :: Value >
104
- where
105
- V : de:: Visitor < ' de > ,
106
- {
107
- // Match an explicit nil as None and everything else as Some
108
- match self . 0 . kind {
109
- ValueKind :: Nil => visitor. visit_none ( ) ,
110
- _ => visitor. visit_some ( self ) ,
111
- }
112
- }
113
-
114
- fn deserialize_enum < V > (
115
- self ,
116
- name : & ' static str ,
117
- variants : & ' static [ & ' static str ] ,
118
- visitor : V ,
119
- ) -> Result < V :: Value >
120
- where
121
- V : de:: Visitor < ' de > ,
122
- {
123
- // FIXME: find a way to extend_with_key
124
- visitor. visit_enum ( EnumAccess { value : self . 0 , name : name, variants : variants } )
125
- }
126
-
127
- forward_to_deserialize_any ! {
128
- char seq
129
- bytes byte_buf map struct unit newtype_struct
130
- identifier ignored_any unit_struct tuple_struct tuple
131
- }
132
- }
6
+ use value:: { Value , ValueKind , Table } ;
133
7
134
8
impl < ' de > de:: Deserializer < ' de > for Value {
135
9
type Error = ConfigError ;
0 commit comments