1
use serde::de::{self, Visitor};
2

            
3
use super::{Error, Result};
4

            
5
pub struct Deserializer<'a, 'b: 'a> {
6
    de: &'a mut super::Deserializer<'b>,
7
    map_as_struct: bool,
8
}
9

            
10
impl<'a, 'b: 'a> Deserializer<'a, 'b> {
11
234093
    pub fn new(de: &'a mut super::Deserializer<'b>, map_as_struct: bool) -> Self {
12
234093
        Deserializer { de, map_as_struct }
13
234093
    }
14
}
15

            
16
impl<'a, 'b: 'a, 'c> de::Deserializer<'b> for &'c mut Deserializer<'a, 'b> {
17
    type Error = Error;
18

            
19
8678
    fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value>
20
8678
    where
21
8678
        V: Visitor<'b>,
22
8678
    {
23
8678
        if self.map_as_struct {
24
            // We only allow string keys in flattened structs and maps
25
612
            self.de.deserialize_str(visitor)
26
        } else {
27
8066
            self.de.deserialize_identifier(visitor)
28
        }
29
8678
    }
30

            
31
8
    fn deserialize_str<V>(self, visitor: V) -> Result<V::Value>
32
8
    where
33
8
        V: Visitor<'b>,
34
8
    {
35
8
        self.deserialize_identifier(visitor)
36
8
    }
37

            
38
12
    fn deserialize_string<V>(self, visitor: V) -> Result<V::Value>
39
12
    where
40
12
        V: Visitor<'b>,
41
12
    {
42
12
        self.deserialize_identifier(visitor)
43
12
    }
44

            
45
6004
    fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>
46
6004
    where
47
6004
        V: Visitor<'b>,
48
6004
    {
49
6004
        self.deserialize_identifier(visitor)
50
6004
    }
51

            
52
4
    fn deserialize_bool<V>(self, _: V) -> Result<V::Value>
53
4
    where
54
4
        V: Visitor<'b>,
55
4
    {
56
4
        Err(Error::ExpectedIdentifier)
57
4
    }
58

            
59
4
    fn deserialize_i8<V>(self, _: V) -> Result<V::Value>
60
4
    where
61
4
        V: Visitor<'b>,
62
4
    {
63
4
        Err(Error::ExpectedIdentifier)
64
4
    }
65

            
66
4
    fn deserialize_i16<V>(self, _: V) -> Result<V::Value>
67
4
    where
68
4
        V: Visitor<'b>,
69
4
    {
70
4
        Err(Error::ExpectedIdentifier)
71
4
    }
72

            
73
4
    fn deserialize_i32<V>(self, _: V) -> Result<V::Value>
74
4
    where
75
4
        V: Visitor<'b>,
76
4
    {
77
4
        Err(Error::ExpectedIdentifier)
78
4
    }
79

            
80
4
    fn deserialize_i64<V>(self, _: V) -> Result<V::Value>
81
4
    where
82
4
        V: Visitor<'b>,
83
4
    {
84
4
        Err(Error::ExpectedIdentifier)
85
4
    }
86

            
87
    #[cfg(feature = "integer128")]
88
2
    fn deserialize_i128<V>(self, _: V) -> Result<V::Value>
89
2
    where
90
2
        V: Visitor<'b>,
91
2
    {
92
2
        Err(Error::ExpectedIdentifier)
93
2
    }
94

            
95
4
    fn deserialize_u8<V>(self, _: V) -> Result<V::Value>
96
4
    where
97
4
        V: Visitor<'b>,
98
4
    {
99
4
        Err(Error::ExpectedIdentifier)
100
4
    }
101

            
102
4
    fn deserialize_u16<V>(self, _: V) -> Result<V::Value>
103
4
    where
104
4
        V: Visitor<'b>,
105
4
    {
106
4
        Err(Error::ExpectedIdentifier)
107
4
    }
108

            
109
4
    fn deserialize_u32<V>(self, _: V) -> Result<V::Value>
110
4
    where
111
4
        V: Visitor<'b>,
112
4
    {
113
4
        Err(Error::ExpectedIdentifier)
114
4
    }
115

            
116
4
    fn deserialize_u64<V>(self, _: V) -> Result<V::Value>
117
4
    where
118
4
        V: Visitor<'b>,
119
4
    {
120
4
        Err(Error::ExpectedIdentifier)
121
4
    }
122

            
123
    #[cfg(feature = "integer128")]
124
2
    fn deserialize_u128<V>(self, _: V) -> Result<V::Value>
125
2
    where
126
2
        V: Visitor<'b>,
127
2
    {
128
2
        Err(Error::ExpectedIdentifier)
129
2
    }
130

            
131
4
    fn deserialize_f32<V>(self, _: V) -> Result<V::Value>
132
4
    where
133
4
        V: Visitor<'b>,
134
4
    {
135
4
        Err(Error::ExpectedIdentifier)
136
4
    }
137

            
138
4
    fn deserialize_f64<V>(self, _: V) -> Result<V::Value>
139
4
    where
140
4
        V: Visitor<'b>,
141
4
    {
142
4
        Err(Error::ExpectedIdentifier)
143
4
    }
144

            
145
4
    fn deserialize_char<V>(self, _: V) -> Result<V::Value>
146
4
    where
147
4
        V: Visitor<'b>,
148
4
    {
149
4
        Err(Error::ExpectedIdentifier)
150
4
    }
151

            
152
4
    fn deserialize_bytes<V>(self, _: V) -> Result<V::Value>
153
4
    where
154
4
        V: Visitor<'b>,
155
4
    {
156
4
        Err(Error::ExpectedIdentifier)
157
4
    }
158

            
159
4
    fn deserialize_byte_buf<V>(self, _: V) -> Result<V::Value>
160
4
    where
161
4
        V: Visitor<'b>,
162
4
    {
163
4
        Err(Error::ExpectedIdentifier)
164
4
    }
165

            
166
4
    fn deserialize_option<V>(self, _: V) -> Result<V::Value>
167
4
    where
168
4
        V: Visitor<'b>,
169
4
    {
170
4
        Err(Error::ExpectedIdentifier)
171
4
    }
172

            
173
4
    fn deserialize_unit<V>(self, _: V) -> Result<V::Value>
174
4
    where
175
4
        V: Visitor<'b>,
176
4
    {
177
4
        Err(Error::ExpectedIdentifier)
178
4
    }
179

            
180
4
    fn deserialize_unit_struct<V>(self, _: &'static str, _: V) -> Result<V::Value>
181
4
    where
182
4
        V: Visitor<'b>,
183
4
    {
184
4
        Err(Error::ExpectedIdentifier)
185
4
    }
186

            
187
4
    fn deserialize_newtype_struct<V>(self, _: &'static str, _: V) -> Result<V::Value>
188
4
    where
189
4
        V: Visitor<'b>,
190
4
    {
191
4
        Err(Error::ExpectedIdentifier)
192
4
    }
193

            
194
4
    fn deserialize_seq<V>(self, _: V) -> Result<V::Value>
195
4
    where
196
4
        V: Visitor<'b>,
197
4
    {
198
4
        Err(Error::ExpectedIdentifier)
199
4
    }
200

            
201
4
    fn deserialize_tuple<V>(self, _: usize, _: V) -> Result<V::Value>
202
4
    where
203
4
        V: Visitor<'b>,
204
4
    {
205
4
        Err(Error::ExpectedIdentifier)
206
4
    }
207

            
208
4
    fn deserialize_tuple_struct<V>(self, _: &'static str, _: usize, _: V) -> Result<V::Value>
209
4
    where
210
4
        V: Visitor<'b>,
211
4
    {
212
4
        Err(Error::ExpectedIdentifier)
213
4
    }
214

            
215
4
    fn deserialize_map<V>(self, _: V) -> Result<V::Value>
216
4
    where
217
4
        V: Visitor<'b>,
218
4
    {
219
4
        Err(Error::ExpectedIdentifier)
220
4
    }
221

            
222
4
    fn deserialize_struct<V>(
223
4
        self,
224
4
        _: &'static str,
225
4
        _: &'static [&'static str],
226
4
        _: V,
227
4
    ) -> Result<V::Value>
228
4
    where
229
4
        V: Visitor<'b>,
230
4
    {
231
4
        Err(Error::ExpectedIdentifier)
232
4
    }
233

            
234
4
    fn deserialize_enum<V>(
235
4
        self,
236
4
        _: &'static str,
237
4
        _: &'static [&'static str],
238
4
        _: V,
239
4
    ) -> Result<V::Value>
240
4
    where
241
4
        V: Visitor<'b>,
242
4
    {
243
4
        Err(Error::ExpectedIdentifier)
244
4
    }
245

            
246
1644
    fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value>
247
1644
    where
248
1644
        V: Visitor<'b>,
249
1644
    {
250
1644
        self.deserialize_any(visitor)
251
1644
    }
252
}