Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use existing helpers for running visit_seq over a Vec/slice #794

Merged
merged 1 commit into from Aug 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 4 additions & 26 deletions src/value/de.rs
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