]> git.proxmox.com Git - rustc.git/blobdiff - src/vendor/serde/src/private/de.rs
New upstream version 1.27.1+dfsg1
[rustc.git] / src / vendor / serde / src / private / de.rs
index 6eae73119868ad1ef905fc03c10af030b1687fb2..026f0cdffc3c5f0da6e2d45de8b2447e3b4759bb 100644 (file)
@@ -11,13 +11,13 @@ use lib::*;
 use de::{Deserialize, DeserializeSeed, Deserializer, Error, IntoDeserializer, Visitor};
 
 #[cfg(any(feature = "std", feature = "alloc"))]
-use de::{Unexpected, MapAccess};
+use de::{MapAccess, Unexpected};
 
 #[cfg(any(feature = "std", feature = "alloc"))]
-pub use self::content::{Content, ContentDeserializer, ContentRefDeserializer,
+pub use self::content::{Content, ContentDeserializer, ContentRefDeserializer, EnumDeserializer,
                         InternallyTaggedUnitVisitor, TagContentOtherField,
                         TagContentOtherFieldVisitor, TagOrContentField, TagOrContentFieldVisitor,
-                        TaggedContentVisitor, UntaggedUnitVisitor, EnumDeserializer};
+                        TaggedContentVisitor, UntaggedUnitVisitor};
 
 /// If the missing field is of type `Option<T>` then treat is as `None`,
 /// otherwise it is an error.
@@ -228,9 +228,9 @@ mod content {
 
     use lib::*;
 
-    use de::{self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, MapAccess, SeqAccess,
-             Unexpected, Visitor};
     use super::size_hint;
+    use de::{self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected, MapAccess,
+             SeqAccess, Unexpected, Visitor};
 
     /// Used from generated code to buffer the contents of the Deserializer when
     /// deserializing untagged enums and internally tagged enums.
@@ -1013,6 +1013,45 @@ mod content {
         err: PhantomData<E>,
     }
 
+    impl<'de, E> ContentDeserializer<'de, E>
+    where
+        E: de::Error,
+    {
+        #[cold]
+        fn invalid_type(self, exp: &Expected) -> E {
+            de::Error::invalid_type(self.content.unexpected(), exp)
+        }
+    }
+
+    fn visit_content_seq<'de, V, E>(content: Vec<Content<'de>>, visitor: V) -> Result<V::Value, E>
+    where
+        V: Visitor<'de>,
+        E: de::Error,
+    {
+        let seq = content.into_iter().map(ContentDeserializer::new);
+        let mut seq_visitor = de::value::SeqDeserializer::new(seq);
+        let value = try!(visitor.visit_seq(&mut seq_visitor));
+        try!(seq_visitor.end());
+        Ok(value)
+    }
+
+    fn visit_content_map<'de, V, E>(
+        content: Vec<(Content<'de>, Content<'de>)>,
+        visitor: V,
+    ) -> Result<V::Value, E>
+    where
+        V: Visitor<'de>,
+        E: de::Error,
+    {
+        let map = content
+            .into_iter()
+            .map(|(k, v)| (ContentDeserializer::new(k), ContentDeserializer::new(v)));
+        let mut map_visitor = de::value::MapDeserializer::new(map);
+        let value = try!(visitor.visit_map(&mut map_visitor));
+        try!(map_visitor.end());
+        Ok(value)
+    }
+
     /// Used when deserializing an internally tagged enum because the content will
     /// be used exactly once.
     impl<'de, E> Deserializer<'de> for ContentDeserializer<'de, E>
@@ -1046,21 +1085,190 @@ mod content {
                 Content::None => visitor.visit_none(),
                 Content::Some(v) => visitor.visit_some(ContentDeserializer::new(*v)),
                 Content::Newtype(v) => visitor.visit_newtype_struct(ContentDeserializer::new(*v)),
-                Content::Seq(v) => {
-                    let seq = v.into_iter().map(ContentDeserializer::new);
-                    let mut seq_visitor = de::value::SeqDeserializer::new(seq);
-                    let value = try!(visitor.visit_seq(&mut seq_visitor));
-                    try!(seq_visitor.end());
-                    Ok(value)
-                }
-                Content::Map(v) => {
-                    let map = v.into_iter()
-                        .map(|(k, v)| (ContentDeserializer::new(k), ContentDeserializer::new(v)));
-                    let mut map_visitor = de::value::MapDeserializer::new(map);
-                    let value = try!(visitor.visit_map(&mut map_visitor));
-                    try!(map_visitor.end());
-                    Ok(value)
-                }
+                Content::Seq(v) => visit_content_seq(v, visitor),
+                Content::Map(v) => visit_content_map(v, visitor),
+            }
+        }
+
+        fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                Content::Bool(v) => visitor.visit_bool(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                Content::I8(v) => visitor.visit_i8(v),
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                Content::I16(v) => visitor.visit_i16(v),
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                Content::I32(v) => visitor.visit_i32(v),
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                Content::U8(v) => visitor.visit_u8(v),
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                Content::U16(v) => visitor.visit_u16(v),
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                Content::U32(v) => visitor.visit_u32(v),
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                Content::F32(v) => visitor.visit_f32(v),
+                Content::F64(v) => visitor.visit_f64(v),
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                Content::F64(v) => visitor.visit_f64(v),
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                Content::Char(v) => visitor.visit_char(v),
+                Content::String(v) => visitor.visit_string(v),
+                Content::Str(v) => visitor.visit_borrowed_str(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            self.deserialize_string(visitor)
+        }
+
+        fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                Content::String(v) => visitor.visit_string(v),
+                Content::Str(v) => visitor.visit_borrowed_str(v),
+                Content::ByteBuf(v) => visitor.visit_byte_buf(v),
+                Content::Bytes(v) => visitor.visit_borrowed_bytes(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            self.deserialize_byte_buf(visitor)
+        }
+
+        fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                Content::String(v) => visitor.visit_string(v),
+                Content::Str(v) => visitor.visit_borrowed_str(v),
+                Content::ByteBuf(v) => visitor.visit_byte_buf(v),
+                Content::Bytes(v) => visitor.visit_borrowed_bytes(v),
+                Content::Seq(v) => visit_content_seq(v, visitor),
+                _ => Err(self.invalid_type(&visitor)),
             }
         }
 
@@ -1076,6 +1284,44 @@ mod content {
             }
         }
 
+        fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                Content::Unit => visitor.visit_unit(),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_unit_struct<V>(
+            self,
+            _name: &'static str,
+            visitor: V,
+        ) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                // As a special case, allow deserializing untagged newtype
+                // variant containing unit struct.
+                //
+                //     #[derive(Deserialize)]
+                //     struct Info;
+                //
+                //     #[derive(Deserialize)]
+                //     #[serde(tag = "topic")]
+                //     enum Message {
+                //         Info(Info),
+                //     }
+                //
+                // We want {"topic":"Info"} to deserialize even though
+                // ordinarily unit structs do not deserialize from empty map.
+                Content::Map(ref v) if v.is_empty() => visitor.visit_unit(),
+                _ => self.deserialize_any(visitor),
+            }
+        }
+
         fn deserialize_newtype_struct<V>(
             self,
             _name: &str,
@@ -1087,6 +1333,61 @@ mod content {
             visitor.visit_newtype_struct(self)
         }
 
+        fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                Content::Seq(v) => visit_content_seq(v, visitor),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            self.deserialize_seq(visitor)
+        }
+
+        fn deserialize_tuple_struct<V>(
+            self,
+            _name: &'static str,
+            _len: usize,
+            visitor: V,
+        ) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            self.deserialize_seq(visitor)
+        }
+
+        fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                Content::Map(v) => visit_content_map(v, visitor),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_struct<V>(
+            self,
+            _name: &'static str,
+            _fields: &'static [&'static str],
+            visitor: V,
+        ) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match self.content {
+                Content::Seq(v) => visit_content_seq(v, visitor),
+                Content::Map(v) => visit_content_map(v, visitor),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
         fn deserialize_enum<V>(
             self,
             _name: &str,
@@ -1129,38 +1430,23 @@ mod content {
             visitor.visit_enum(EnumDeserializer::new(variant, value))
         }
 
-        fn deserialize_unit_struct<V>(
-            self,
-            _name: &'static str,
-            visitor: V,
-        ) -> Result<V::Value, Self::Error>
+        fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>
         where
             V: Visitor<'de>,
         {
             match self.content {
-                // As a special case, allow deserializing untagged newtype
-                // variant containing unit struct.
-                //
-                //     #[derive(Deserialize)]
-                //     struct Info;
-                //
-                //     #[derive(Deserialize)]
-                //     #[serde(tag = "topic")]
-                //     enum Message {
-                //         Info(Info),
-                //     }
-                //
-                // We want {"topic":"Info"} to deserialize even though
-                // ordinarily unit structs do not deserialize from empty map.
-                Content::Map(ref v) if v.is_empty() => visitor.visit_unit(),
-                _ => self.deserialize_any(visitor),
+                Content::String(v) => visitor.visit_string(v),
+                Content::Str(v) => visitor.visit_borrowed_str(v),
+                _ => Err(self.invalid_type(&visitor)),
             }
         }
 
-        forward_to_deserialize_any! {
-            bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char str string bytes
-            byte_buf unit seq tuple tuple_struct map struct identifier
-            ignored_any
+        fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            drop(self);
+            visitor.visit_unit()
         }
     }
 
@@ -1184,7 +1470,8 @@ mod content {
     }
 
     impl<'de, E> EnumDeserializer<'de, E>
-        where E: de::Error
+    where
+        E: de::Error,
     {
         pub fn new(variant: Content<'de>, value: Option<Content<'de>>) -> EnumDeserializer<'de, E> {
             EnumDeserializer {
@@ -1451,6 +1738,51 @@ mod content {
         err: PhantomData<E>,
     }
 
+    impl<'a, 'de, E> ContentRefDeserializer<'a, 'de, E>
+    where
+        E: de::Error,
+    {
+        #[cold]
+        fn invalid_type(self, exp: &Expected) -> E {
+            de::Error::invalid_type(self.content.unexpected(), exp)
+        }
+    }
+
+    fn visit_content_seq_ref<'a, 'de, V, E>(
+        content: &'a [Content<'de>],
+        visitor: V,
+    ) -> Result<V::Value, E>
+    where
+        V: Visitor<'de>,
+        E: de::Error,
+    {
+        let seq = content.into_iter().map(ContentRefDeserializer::new);
+        let mut seq_visitor = de::value::SeqDeserializer::new(seq);
+        let value = try!(visitor.visit_seq(&mut seq_visitor));
+        try!(seq_visitor.end());
+        Ok(value)
+    }
+
+    fn visit_content_map_ref<'a, 'de, V, E>(
+        content: &'a [(Content<'de>, Content<'de>)],
+        visitor: V,
+    ) -> Result<V::Value, E>
+    where
+        V: Visitor<'de>,
+        E: de::Error,
+    {
+        let map = content.into_iter().map(|&(ref k, ref v)| {
+            (
+                ContentRefDeserializer::new(k),
+                ContentRefDeserializer::new(v),
+            )
+        });
+        let mut map_visitor = de::value::MapDeserializer::new(map);
+        let value = try!(visitor.visit_map(&mut map_visitor));
+        try!(map_visitor.end());
+        Ok(value)
+    }
+
     /// Used when deserializing an untagged enum because the content may need to be
     /// used more than once.
     impl<'de, 'a, E> Deserializer<'de> for ContentRefDeserializer<'a, 'de, E>
@@ -1486,28 +1818,193 @@ mod content {
                 Content::Newtype(ref v) => {
                     visitor.visit_newtype_struct(ContentRefDeserializer::new(v))
                 }
-                Content::Seq(ref v) => {
-                    let seq = v.into_iter().map(ContentRefDeserializer::new);
-                    let mut seq_visitor = de::value::SeqDeserializer::new(seq);
-                    let value = try!(visitor.visit_seq(&mut seq_visitor));
-                    try!(seq_visitor.end());
-                    Ok(value)
-                }
-                Content::Map(ref v) => {
-                    let map = v.into_iter().map(|&(ref k, ref v)| {
-                        (
-                            ContentRefDeserializer::new(k),
-                            ContentRefDeserializer::new(v),
-                        )
-                    });
-                    let mut map_visitor = de::value::MapDeserializer::new(map);
-                    let value = try!(visitor.visit_map(&mut map_visitor));
-                    try!(map_visitor.end());
-                    Ok(value)
-                }
+                Content::Seq(ref v) => visit_content_seq_ref(v, visitor),
+                Content::Map(ref v) => visit_content_map_ref(v, visitor),
+            }
+        }
+
+        fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match *self.content {
+                Content::Bool(v) => visitor.visit_bool(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match *self.content {
+                Content::I8(v) => visitor.visit_i8(v),
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match *self.content {
+                Content::I16(v) => visitor.visit_i16(v),
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match *self.content {
+                Content::I32(v) => visitor.visit_i32(v),
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match *self.content {
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match *self.content {
+                Content::U8(v) => visitor.visit_u8(v),
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match *self.content {
+                Content::U16(v) => visitor.visit_u16(v),
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match *self.content {
+                Content::U32(v) => visitor.visit_u32(v),
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match *self.content {
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match *self.content {
+                Content::F32(v) => visitor.visit_f32(v),
+                Content::F64(v) => visitor.visit_f64(v),
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match *self.content {
+                Content::F64(v) => visitor.visit_f64(v),
+                Content::U64(v) => visitor.visit_u64(v),
+                Content::I64(v) => visitor.visit_i64(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match *self.content {
+                Content::Char(v) => visitor.visit_char(v),
+                Content::String(ref v) => visitor.visit_str(v),
+                Content::Str(v) => visitor.visit_borrowed_str(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match *self.content {
+                Content::String(ref v) => visitor.visit_str(v),
+                Content::Str(v) => visitor.visit_borrowed_str(v),
+                Content::ByteBuf(ref v) => visitor.visit_bytes(v),
+                Content::Bytes(v) => visitor.visit_borrowed_bytes(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            self.deserialize_str(visitor)
+        }
+
+        fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match *self.content {
+                Content::String(ref v) => visitor.visit_str(v),
+                Content::Str(v) => visitor.visit_borrowed_str(v),
+                Content::ByteBuf(ref v) => visitor.visit_bytes(v),
+                Content::Bytes(v) => visitor.visit_borrowed_bytes(v),
+                Content::Seq(ref v) => visit_content_seq_ref(v, visitor),
+                _ => Err(self.invalid_type(&visitor)),
             }
         }
 
+        fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            self.deserialize_bytes(visitor)
+        }
+
         fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, E>
         where
             V: Visitor<'de>,
@@ -1520,6 +2017,27 @@ mod content {
             }
         }
 
+        fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match *self.content {
+                Content::Unit => visitor.visit_unit(),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_unit_struct<V>(
+            self,
+            _name: &'static str,
+            visitor: V,
+        ) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            self.deserialize_unit(visitor)
+        }
+
         fn deserialize_newtype_struct<V>(self, _name: &str, visitor: V) -> Result<V::Value, E>
         where
             V: Visitor<'de>,
@@ -1527,6 +2045,61 @@ mod content {
             visitor.visit_newtype_struct(self)
         }
 
+        fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match *self.content {
+                Content::Seq(ref v) => visit_content_seq_ref(v, visitor),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            self.deserialize_seq(visitor)
+        }
+
+        fn deserialize_tuple_struct<V>(
+            self,
+            _name: &'static str,
+            _len: usize,
+            visitor: V,
+        ) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            self.deserialize_seq(visitor)
+        }
+
+        fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match *self.content {
+                Content::Map(ref v) => visit_content_map_ref(v, visitor),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_struct<V>(
+            self,
+            _name: &'static str,
+            _fields: &'static [&'static str],
+            visitor: V,
+        ) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match *self.content {
+                Content::Seq(ref v) => visit_content_seq_ref(v, visitor),
+                Content::Map(ref v) => visit_content_map_ref(v, visitor),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
         fn deserialize_enum<V>(
             self,
             _name: &str,
@@ -1573,10 +2146,22 @@ mod content {
             })
         }
 
-        forward_to_deserialize_any! {
-            bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char str string bytes
-            byte_buf unit unit_struct seq tuple tuple_struct map struct
-            identifier ignored_any
+        fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            match *self.content {
+                Content::String(ref v) => visitor.visit_str(v),
+                Content::Str(v) => visitor.visit_borrowed_str(v),
+                _ => Err(self.invalid_type(&visitor)),
+            }
+        }
+
+        fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
+        where
+            V: Visitor<'de>,
+        {
+            visitor.visit_unit()
         }
     }
 
@@ -2082,12 +2667,13 @@ where
 #[cfg(any(feature = "std", feature = "alloc"))]
 pub struct FlatMapDeserializer<'a, 'de: 'a, E>(
     pub &'a mut Vec<Option<(Content<'de>, Content<'de>)>>,
-    pub PhantomData<E>
+    pub PhantomData<E>,
 );
 
 #[cfg(any(feature = "std", feature = "alloc"))]
 impl<'a, 'de, E> Deserializer<'de> for FlatMapDeserializer<'a, 'de, E>
-    where E: Error
+where
+    E: Error,
 {
     type Error = E;
 
@@ -2102,7 +2688,7 @@ impl<'a, 'de, E> Deserializer<'de> for FlatMapDeserializer<'a, 'de, E>
         self,
         name: &'static str,
         variants: &'static [&'static str],
-        visitor: V
+        visitor: V,
     ) -> Result<V::Value, Self::Error>
     where
         V: Visitor<'de>,
@@ -2113,15 +2699,12 @@ impl<'a, 'de, E> Deserializer<'de> for FlatMapDeserializer<'a, 'de, E>
             // about.
             let use_item = match *item {
                 None => false,
-                Some((ref c, _)) => c.as_str().map_or(false, |x| variants.contains(&x))
+                Some((ref c, _)) => c.as_str().map_or(false, |x| variants.contains(&x)),
             };
 
             if use_item {
                 let (key, value) = item.take().unwrap();
-                return visitor.visit_enum(EnumDeserializer::new(
-                    key,
-                    Some(value)
-                ));
+                return visitor.visit_enum(EnumDeserializer::new(key, Some(value)));
             }
         }
 
@@ -2142,7 +2725,7 @@ impl<'a, 'de, E> Deserializer<'de> for FlatMapDeserializer<'a, 'de, E>
         self,
         _: &'static str,
         fields: &'static [&'static str],
-        visitor: V
+        visitor: V,
     ) -> Result<V::Value, Self::Error>
     where
         V: Visitor<'de>,
@@ -2150,11 +2733,7 @@ impl<'a, 'de, E> Deserializer<'de> for FlatMapDeserializer<'a, 'de, E>
         visitor.visit_map(FlatMapAccess::new(self.0.iter_mut(), Some(fields)))
     }
 
-    fn deserialize_newtype_struct<V>(
-        self,
-        _name: &str,
-        visitor: V,
-    ) -> Result<V::Value, Self::Error>
+    fn deserialize_newtype_struct<V>(self, _name: &str, visitor: V) -> Result<V::Value, Self::Error>
     where
         V: Visitor<'de>,
     {
@@ -2180,7 +2759,7 @@ pub struct FlatMapAccess<'a, 'de: 'a, E> {
 impl<'a, 'de, E> FlatMapAccess<'a, 'de, E> {
     fn new(
         iter: slice::IterMut<'a, Option<(Content<'de>, Content<'de>)>>,
-        fields: Option<&'static [&'static str]>
+        fields: Option<&'static [&'static str]>,
     ) -> FlatMapAccess<'a, 'de, E> {
         FlatMapAccess {
             iter: iter,
@@ -2193,7 +2772,8 @@ impl<'a, 'de, E> FlatMapAccess<'a, 'de, E> {
 
 #[cfg(any(feature = "std", feature = "alloc"))]
 impl<'a, 'de, E> MapAccess<'de> for FlatMapAccess<'a, 'de, E>
-    where E: Error
+where
+    E: Error,
 {
     type Error = E;
 
@@ -2208,13 +2788,12 @@ impl<'a, 'de, E> MapAccess<'de> for FlatMapAccess<'a, 'de, E>
             let use_item = match *item {
                 None => false,
                 Some((ref c, _)) => {
-                    c.as_str().map_or(self.fields.is_none(), |key| {
-                        match self.fields {
+                    c.as_str()
+                        .map_or(self.fields.is_none(), |key| match self.fields {
                             None => true,
                             Some(fields) if fields.contains(&key) => true,
-                            _ => false
-                        }
-                    })
+                            _ => false,
+                        })
                 }
             };