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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
pub struct NullDeserializer;
use serde::de::{self, Deserializer, MapAccess, Error as ErrorTrait, Visitor};
use erased_serde::Error;

impl<'de> Deserializer<'de> for NullDeserializer {
    type Error = Error;
    fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
        where V: Visitor<'de>,
    {
        visitor.visit_map(NullMapAccessor)
    }

    fn deserialize_struct<V>(
        self,
        _name: &'static str,
        _fields: &'static [&'static str],
        visitor: V,
    ) -> Result<V::Value, Self::Error>
        where V: Visitor<'de>,
    {
        visitor.visit_map(NullMapAccessor)
    }

    fn deserialize_tuple_struct<V>(
        self,
        _name: &'static str,
        _fields: usize,
        visitor: V
    ) -> Result<V::Value, Self::Error>
        where V: Visitor<'de>, 
    {
        visitor.visit_map(NullMapAccessor)
    }

    fn deserialize_newtype_struct<V>(
        self,
        _name: &'static str,
        visitor: V
    ) -> Result<V::Value, Self::Error>
        where V: Visitor<'de>, 
    {
        visitor.visit_map(NullMapAccessor)
    }


    fn deserialize_unit_struct<V>(
        self,
        _name: &'static str,
        visitor: V
    ) -> Result<V::Value, Self::Error>
        where V: Visitor<'de>, 
    {
        visitor.visit_map(NullMapAccessor)
    }

    forward_to_deserialize_any! {
        bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit seq
        bytes byte_buf map
        tuple ignored_any identifier enum option 
    }
}

struct NullMapAccessor;

impl<'de> MapAccess<'de> for NullMapAccessor {
    type Error = Error;

    fn next_key_seed<K>(&mut self, _seed: K) -> Result<Option<K::Value>, Self::Error>
        where K: de::DeserializeSeed<'de>,
    {
        Ok(None)
    }

    fn next_value_seed<V>(&mut self, _seed: V) -> Result<V::Value, Self::Error>
        where V: de::DeserializeSeed<'de>, 
    {
        Err(Error::custom("called `next_value` without calling `next_key`"))
    }
}