Merge pull request #375 from canndrew/fix-serde-struct-macros

Fix serde struct macros deserialization impls
This commit is contained in:
Steven Roose 2020-04-19 19:56:27 +01:00 committed by GitHub
commit a9173d61d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 44 additions and 0 deletions

View File

@ -282,6 +282,28 @@ macro_rules! serde_struct_impl {
formatter.write_str("a struct")
}
fn visit_seq<V>(self, mut seq: V) -> Result<Self::Value, V::Error>
where
V: $crate::serde::de::SeqAccess<'de>,
{
use $crate::serde::de::Error;
let length = 0;
$(
let $fe = seq.next_element()?.ok_or_else(|| {
Error::invalid_length(length, &self)
})?;
#[allow(unused_variables)]
let length = length + 1;
)*
let ret = $name {
$($fe: $fe),*
};
Ok(ret)
}
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
where
A: $crate::serde::de::MapAccess<'de>,
@ -498,6 +520,28 @@ macro_rules! serde_struct_human_string_impl {
formatter.write_str("a struct")
}
fn visit_seq<V>(self, mut seq: V) -> Result<Self::Value, V::Error>
where
V: $crate::serde::de::SeqAccess<'de>,
{
use $crate::serde::de::Error;
let length = 0;
$(
let $fe = seq.next_element()?.ok_or_else(|| {
Error::invalid_length(length, &self)
})?;
#[allow(unused_variables)]
let length = length + 1;
)*
let ret = $name {
$($fe: $fe),*
};
Ok(ret)
}
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
where
A: $crate::serde::de::MapAccess<'de>,