1 use serde
::de
::IntoDeserializer
;
5 impl<'de
, 'a
> serde
::Deserializer
<'de
> for crate::Table
{
8 fn deserialize_any
<V
>(self, visitor
: V
) -> Result
<V
::Value
, Self::Error
>
10 V
: serde
::de
::Visitor
<'de
>,
12 visitor
.visit_map(crate::de
::TableMapAccess
::new(self))
15 // `None` is interpreted as a missing field so be sure to implement `Some`
16 // as a present field.
17 fn deserialize_option
<V
>(self, visitor
: V
) -> Result
<V
::Value
, Error
>
19 V
: serde
::de
::Visitor
<'de
>,
21 visitor
.visit_some(self)
24 fn deserialize_newtype_struct
<V
>(
28 ) -> Result
<V
::Value
, Error
>
30 V
: serde
::de
::Visitor
<'de
>,
32 visitor
.visit_newtype_struct(self)
35 fn deserialize_struct
<V
>(
38 _fields
: &'
static [&'
static str],
40 ) -> Result
<V
::Value
, Error
>
42 V
: serde
::de
::Visitor
<'de
>,
44 self.deserialize_any(visitor
)
47 // Called when the type to deserialize is an enum, as opposed to a field in the type.
48 fn deserialize_enum
<V
>(
51 _variants
: &'
static [&'
static str],
53 ) -> Result
<V
::Value
, Error
>
55 V
: serde
::de
::Visitor
<'de
>,
58 Err(crate::de
::Error
::custom(
59 "wanted exactly 1 element, found 0 elements",
61 } else if self.len() != 1 {
62 Err(crate::de
::Error
::custom(
63 "wanted exactly 1 element, more than 1 element",
66 visitor
.visit_enum(crate::de
::TableMapAccess
::new(self))
70 serde
::forward_to_deserialize_any
! {
71 bool
u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq
72 bytes byte_buf map unit
73 ignored_any unit_struct tuple_struct tuple identifier
77 impl<'de
> serde
::de
::IntoDeserializer
<'de
, crate::de
::Error
> for crate::Table
{
78 type Deserializer
= Self;
80 fn into_deserializer(self) -> Self {
85 pub(crate) struct TableMapAccess
{
86 iter
: indexmap
::map
::IntoIter
<crate::InternalString
, crate::table
::TableKeyValue
>,
87 value
: Option
<(crate::InternalString
, crate::Item
)>,
91 pub(crate) fn new(input
: crate::Table
) -> Self {
93 iter
: input
.items
.into_iter(),
99 impl<'de
> serde
::de
::MapAccess
<'de
> for TableMapAccess
{
102 fn next_key_seed
<K
>(&mut self, seed
: K
) -> Result
<Option
<K
::Value
>, Self::Error
>
104 K
: serde
::de
::DeserializeSeed
<'de
>,
106 match self.iter
.next() {
108 let ret
= seed
.deserialize(k
.into_deserializer()).map(Some
);
109 self.value
= Some((k
, v
.value
));
116 fn next_value_seed
<V
>(&mut self, seed
: V
) -> Result
<V
::Value
, Self::Error
>
118 V
: serde
::de
::DeserializeSeed
<'de
>,
120 match self.value
.take() {
122 .deserialize(crate::de
::ItemDeserializer
::new(v
))
128 panic
!("no more values in next_value_seed, internal error in ItemDeserializer")
134 impl<'de
> serde
::de
::EnumAccess
<'de
> for TableMapAccess
{
136 type Variant
= super::TableEnumDeserializer
;
138 fn variant_seed
<V
>(mut self, seed
: V
) -> Result
<(V
::Value
, Self::Variant
), Self::Error
>
140 V
: serde
::de
::DeserializeSeed
<'de
>,
142 let (key
, value
) = match self.iter
.next() {
145 return Err(Error
::custom(
146 "expected table with exactly 1 entry, found empty table",
151 seed
.deserialize(key
.into_deserializer())
152 .map(|val
| (val
, super::TableEnumDeserializer
::new(value
.value
)))