ron/de/
id.rs

1use serde::de::{self, Visitor};
2
3use super::{Error, Result};
4
5pub struct Deserializer<'a, 'b: 'a> {
6    de: &'a mut super::Deserializer<'b>,
7    map_as_struct: bool,
8}
9
10impl<'a, 'b: 'a> Deserializer<'a, 'b> {
11    pub fn new(de: &'a mut super::Deserializer<'b>, map_as_struct: bool) -> Self {
12        Deserializer { de, map_as_struct }
13    }
14}
15
16impl<'a, 'b: 'a, 'c> de::Deserializer<'b> for &'c mut Deserializer<'a, 'b> {
17    type Error = Error;
18
19    fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value>
20    where
21        V: Visitor<'b>,
22    {
23        if self.map_as_struct {
24            // We only allow string keys in flattened structs and maps
25            self.de.deserialize_str(visitor)
26        } else {
27            self.de.deserialize_identifier(visitor)
28        }
29    }
30
31    fn deserialize_str<V>(self, visitor: V) -> Result<V::Value>
32    where
33        V: Visitor<'b>,
34    {
35        self.deserialize_identifier(visitor)
36    }
37
38    fn deserialize_string<V>(self, visitor: V) -> Result<V::Value>
39    where
40        V: Visitor<'b>,
41    {
42        self.deserialize_identifier(visitor)
43    }
44
45    fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>
46    where
47        V: Visitor<'b>,
48    {
49        self.deserialize_identifier(visitor)
50    }
51
52    fn deserialize_bool<V>(self, _: V) -> Result<V::Value>
53    where
54        V: Visitor<'b>,
55    {
56        Err(Error::ExpectedIdentifier)
57    }
58
59    fn deserialize_i8<V>(self, _: V) -> Result<V::Value>
60    where
61        V: Visitor<'b>,
62    {
63        Err(Error::ExpectedIdentifier)
64    }
65
66    fn deserialize_i16<V>(self, _: V) -> Result<V::Value>
67    where
68        V: Visitor<'b>,
69    {
70        Err(Error::ExpectedIdentifier)
71    }
72
73    fn deserialize_i32<V>(self, _: V) -> Result<V::Value>
74    where
75        V: Visitor<'b>,
76    {
77        Err(Error::ExpectedIdentifier)
78    }
79
80    fn deserialize_i64<V>(self, _: V) -> Result<V::Value>
81    where
82        V: Visitor<'b>,
83    {
84        Err(Error::ExpectedIdentifier)
85    }
86
87    #[cfg(feature = "integer128")]
88    fn deserialize_i128<V>(self, _: V) -> Result<V::Value>
89    where
90        V: Visitor<'b>,
91    {
92        Err(Error::ExpectedIdentifier)
93    }
94
95    fn deserialize_u8<V>(self, _: V) -> Result<V::Value>
96    where
97        V: Visitor<'b>,
98    {
99        Err(Error::ExpectedIdentifier)
100    }
101
102    fn deserialize_u16<V>(self, _: V) -> Result<V::Value>
103    where
104        V: Visitor<'b>,
105    {
106        Err(Error::ExpectedIdentifier)
107    }
108
109    fn deserialize_u32<V>(self, _: V) -> Result<V::Value>
110    where
111        V: Visitor<'b>,
112    {
113        Err(Error::ExpectedIdentifier)
114    }
115
116    fn deserialize_u64<V>(self, _: V) -> Result<V::Value>
117    where
118        V: Visitor<'b>,
119    {
120        Err(Error::ExpectedIdentifier)
121    }
122
123    #[cfg(feature = "integer128")]
124    fn deserialize_u128<V>(self, _: V) -> Result<V::Value>
125    where
126        V: Visitor<'b>,
127    {
128        Err(Error::ExpectedIdentifier)
129    }
130
131    fn deserialize_f32<V>(self, _: V) -> Result<V::Value>
132    where
133        V: Visitor<'b>,
134    {
135        Err(Error::ExpectedIdentifier)
136    }
137
138    fn deserialize_f64<V>(self, _: V) -> Result<V::Value>
139    where
140        V: Visitor<'b>,
141    {
142        Err(Error::ExpectedIdentifier)
143    }
144
145    fn deserialize_char<V>(self, _: V) -> Result<V::Value>
146    where
147        V: Visitor<'b>,
148    {
149        Err(Error::ExpectedIdentifier)
150    }
151
152    fn deserialize_bytes<V>(self, _: V) -> Result<V::Value>
153    where
154        V: Visitor<'b>,
155    {
156        Err(Error::ExpectedIdentifier)
157    }
158
159    fn deserialize_byte_buf<V>(self, _: V) -> Result<V::Value>
160    where
161        V: Visitor<'b>,
162    {
163        Err(Error::ExpectedIdentifier)
164    }
165
166    fn deserialize_option<V>(self, _: V) -> Result<V::Value>
167    where
168        V: Visitor<'b>,
169    {
170        Err(Error::ExpectedIdentifier)
171    }
172
173    fn deserialize_unit<V>(self, _: V) -> Result<V::Value>
174    where
175        V: Visitor<'b>,
176    {
177        Err(Error::ExpectedIdentifier)
178    }
179
180    fn deserialize_unit_struct<V>(self, _: &'static str, _: V) -> Result<V::Value>
181    where
182        V: Visitor<'b>,
183    {
184        Err(Error::ExpectedIdentifier)
185    }
186
187    fn deserialize_newtype_struct<V>(self, _: &'static str, _: V) -> Result<V::Value>
188    where
189        V: Visitor<'b>,
190    {
191        Err(Error::ExpectedIdentifier)
192    }
193
194    fn deserialize_seq<V>(self, _: V) -> Result<V::Value>
195    where
196        V: Visitor<'b>,
197    {
198        Err(Error::ExpectedIdentifier)
199    }
200
201    fn deserialize_tuple<V>(self, _: usize, _: V) -> Result<V::Value>
202    where
203        V: Visitor<'b>,
204    {
205        Err(Error::ExpectedIdentifier)
206    }
207
208    fn deserialize_tuple_struct<V>(self, _: &'static str, _: usize, _: V) -> Result<V::Value>
209    where
210        V: Visitor<'b>,
211    {
212        Err(Error::ExpectedIdentifier)
213    }
214
215    fn deserialize_map<V>(self, _: V) -> Result<V::Value>
216    where
217        V: Visitor<'b>,
218    {
219        Err(Error::ExpectedIdentifier)
220    }
221
222    fn deserialize_struct<V>(
223        self,
224        _: &'static str,
225        _: &'static [&'static str],
226        _: V,
227    ) -> Result<V::Value>
228    where
229        V: Visitor<'b>,
230    {
231        Err(Error::ExpectedIdentifier)
232    }
233
234    fn deserialize_enum<V>(
235        self,
236        _: &'static str,
237        _: &'static [&'static str],
238        _: V,
239    ) -> Result<V::Value>
240    where
241        V: Visitor<'b>,
242    {
243        Err(Error::ExpectedIdentifier)
244    }
245
246    fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value>
247    where
248        V: Visitor<'b>,
249    {
250        self.deserialize_any(visitor)
251    }
252}