Skip to content

Commit

Permalink
Merge pull request #793 from dtolnay/valuede
Browse files Browse the repository at this point in the history
Delete several other superfluous Deserializer impls
  • Loading branch information
dtolnay authored Aug 28, 2021
2 parents ac9078e + cdc2ad3 commit 604d5cf
Showing 1 changed file with 33 additions and 87 deletions.
120 changes: 33 additions & 87 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 Expand Up @@ -1023,7 +1006,22 @@ impl<'de> VariantAccess<'de> for VariantRefDeserializer<'de> {
{
match self.value {
Some(&Value::Array(ref v)) => {
serde::Deserializer::deserialize_any(SeqRefDeserializer::new(v), visitor)
let len = v.len();
if len == 0 {
visitor.visit_unit()
} else {
let mut seq = SeqRefDeserializer::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 All @@ -1045,9 +1043,7 @@ impl<'de> VariantAccess<'de> for VariantRefDeserializer<'de> {
V: Visitor<'de>,
{
match self.value {
Some(&Value::Object(ref v)) => {
serde::Deserializer::deserialize_any(MapRefDeserializer::new(v), visitor)
}
Some(&Value::Object(ref v)) => visitor.visit_map(MapRefDeserializer::new(v)),
Some(other) => Err(serde::de::Error::invalid_type(
other.unexpected(),
&"struct variant",
Expand All @@ -1070,38 +1066,6 @@ impl<'de> SeqRefDeserializer<'de> {
}
}

impl<'de> serde::Deserializer<'de> for SeqRefDeserializer<'de> {
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 SeqRefDeserializer<'de> {
type Error = Error;

Expand Down Expand Up @@ -1174,24 +1138,6 @@ impl<'de> MapAccess<'de> for MapRefDeserializer<'de> {
}
}

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

#[inline]
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
visitor.visit_map(self)
}

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
}
}

struct MapKeyDeserializer<'de> {
key: Cow<'de, str>,
}
Expand Down

0 comments on commit 604d5cf

Please sign in to comment.