From 89cfb456ffc0749e2e30321e2196b1c8c29e1e00 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 28 Aug 2021 11:03:27 -0700 Subject: [PATCH] Use existing helpers for running visit_seq over a Vec/slice --- src/value/de.rs | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/src/value/de.rs b/src/value/de.rs index f5f87bcbb..5ff011961 100644 --- a/src/value/de.rs +++ b/src/value/de.rs @@ -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( @@ -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(