1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use crate::des::wrapper::MapKeyDeserializer;
use crate::des::{deserializer::Deserializer, read::Read};
use crate::error::{Error, ErrorCode, Result};
use serde::de;
pub(crate) struct InitMapAccess<'a, R: 'a> {
pub(super) des: &'a mut Deserializer<R>,
}
impl<'a, R: 'a> InitMapAccess<'a, R> {
pub(crate) fn new(des: &'a mut Deserializer<R>) -> Self {
InitMapAccess { des }
}
}
impl<'de, 'a, R: Read<'de> + 'a> de::MapAccess<'de> for InitMapAccess<'a, R> {
type Error = Error;
fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>>
where
K: de::DeserializeSeed<'de>,
{
match self.des.parse_whitespace()? {
/* Some(b' ') if !self.first => {
self.de.eat_char();
self.de.parse_whitespace()?
}
Some(b) => {
if self.first {
self.first = false;
Some(b)
} else {
return Err(self.de.peek_error(ErrorCode::ExpectedObjectCommaOrEnd));
}
} */
Some(b'}') => Err(self.des.peek_error(ErrorCode::TrailingComma)),
Some(_) => seed
.deserialize(MapKeyDeserializer { des: self.des })
.map(Some),
None => Ok(None),
}
/* match peek {
// Some(b'"') => seed.deserialize(MapKey { de: &mut *self.de }).map(Some),
Some(b'}') => Err(self.de.peek_error(ErrorCode::TrailingComma)),
// Some(_) => Err(self.de.peek_error(ErrorCode::KeyMustBeAString)),
Some(_) => seed.deserialize(MapKey { de: &mut *self.de }).map(Some),
None => Err(self.de.peek_error(ErrorCode::EofWhileParsingValue)),
} */
}
#[inline]
fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value>
where
V: de::DeserializeSeed<'de>,
{
self.des.parse_object_colon()?;
seed.deserialize(&mut *self.des)
}
}