Skip to content

Commit

Permalink
Delete Deserializer impl from value::de::SeqDeserializer
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Aug 28, 2021
1 parent ac9078e commit fcd94f0
Showing 1 changed file with 16 additions and 33 deletions.
49 changes: 16 additions & 33 deletions src/value/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -559,38 +574,6 @@ impl SeqDeserializer {
}
}

impl<'de> serde::Deserializer<'de> for SeqDeserializer {
type Error = Error;

#[inline]
fn deserialize_any<V>(mut self, visitor: V) -> Result<V::Value, Error>
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;

Expand Down

0 comments on commit fcd94f0

Please sign in to comment.