Skip to content

Commit

Permalink
Use existing helpers for running visit_seq over a Vec/slice
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Aug 28, 2021
1 parent 604d5cf commit 89cfb45
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions src/value/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,21 +512,10 @@ impl<'de> VariantAccess<'de> for VariantDeserializer {
{
match self.value {
Some(Value::Array(v)) => {
let len = v.len();
if len == 0 {
if v.is_empty() {
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",
))
}
visit_array(v, visitor)
}
}
Some(other) => Err(serde::de::Error::invalid_type(
Expand Down Expand Up @@ -1006,21 +995,10 @@ impl<'de> VariantAccess<'de> for VariantRefDeserializer<'de> {
{
match self.value {
Some(&Value::Array(ref v)) => {
let len = v.len();
if len == 0 {
if v.is_empty() {
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",
))
}
visit_array_ref(v, visitor)
}
}
Some(other) => Err(serde::de::Error::invalid_type(
Expand Down

0 comments on commit 89cfb45

Please sign in to comment.