diff --git a/src/value/de.rs b/src/value/de.rs index da216831b..94fdecd9b 100644 --- a/src/value/de.rs +++ b/src/value/de.rs @@ -512,7 +512,22 @@ impl<'de> VariantAccess<'de> for VariantDeserializer { { match self.value { Some(Value::Array(v)) => { - serde::Deserializer::deserialize_any(SeqDeserializer::new(v), visitor) + let len = v.len(); + if len == 0 { + visitor.visit_unit() + } else { + let mut seq = SeqDeserializer::new(v); + let ret = tri!(visitor.visit_seq(&mut seq)); + let remaining = seq.iter.len(); + if remaining == 0 { + Ok(ret) + } else { + Err(serde::de::Error::invalid_length( + len, + &"fewer elements in array", + )) + } + } } Some(other) => Err(serde::de::Error::invalid_type( other.unexpected(), @@ -559,38 +574,6 @@ impl SeqDeserializer { } } -impl<'de> serde::Deserializer<'de> for SeqDeserializer { - type Error = Error; - - #[inline] - fn deserialize_any(mut self, visitor: V) -> Result - where - V: Visitor<'de>, - { - let len = self.iter.len(); - if len == 0 { - visitor.visit_unit() - } else { - let ret = tri!(visitor.visit_seq(&mut self)); - let remaining = self.iter.len(); - if remaining == 0 { - Ok(ret) - } else { - Err(serde::de::Error::invalid_length( - len, - &"fewer elements in array", - )) - } - } - } - - forward_to_deserialize_any! { - bool i8 i16 i32 i64 i128 u8 u16 u32 u64 u128 f32 f64 char str string - bytes byte_buf option unit unit_struct newtype_struct seq tuple - tuple_struct map struct enum identifier ignored_any - } -} - impl<'de> SeqAccess<'de> for SeqDeserializer { type Error = Error;