mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-18 09:41:12 +00:00
Generate visit_seq only when needed
This commit is contained in:
+22
-20
@@ -942,10 +942,6 @@ fn deserialize_struct(
|
|||||||
};
|
};
|
||||||
let expecting = cattrs.expecting().unwrap_or(&expecting);
|
let expecting = cattrs.expecting().unwrap_or(&expecting);
|
||||||
|
|
||||||
let visit_seq = Stmts(deserialize_seq(
|
|
||||||
&type_path, params, fields, true, cattrs, expecting,
|
|
||||||
));
|
|
||||||
|
|
||||||
let (field_visitor, fields_stmt, visit_map) = if cattrs.has_flatten() {
|
let (field_visitor, fields_stmt, visit_map) = if cattrs.has_flatten() {
|
||||||
deserialize_struct_as_map_visitor(&type_path, params, fields, cattrs)
|
deserialize_struct_as_map_visitor(&type_path, params, fields, cattrs)
|
||||||
} else {
|
} else {
|
||||||
@@ -985,25 +981,31 @@ fn deserialize_struct(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let all_skipped = fields.iter().all(|field| field.attrs.skip_deserializing());
|
|
||||||
let visitor_var = if all_skipped {
|
|
||||||
quote!(_)
|
|
||||||
} else {
|
|
||||||
quote!(mut __seq)
|
|
||||||
};
|
|
||||||
|
|
||||||
// untagged struct variants do not get a visit_seq method. The same applies to
|
// untagged struct variants do not get a visit_seq method. The same applies to
|
||||||
// structs that only have a map representation.
|
// structs that only have a map representation.
|
||||||
let visit_seq = match *untagged {
|
let visit_seq = match *untagged {
|
||||||
Untagged::No if !cattrs.has_flatten() => Some(quote! {
|
Untagged::No if !cattrs.has_flatten() => {
|
||||||
#[inline]
|
let all_skipped = fields.iter().all(|field| field.attrs.skip_deserializing());
|
||||||
fn visit_seq<__A>(self, #visitor_var: __A) -> _serde::__private::Result<Self::Value, __A::Error>
|
let mut_seq = if all_skipped {
|
||||||
where
|
quote!(_)
|
||||||
__A: _serde::de::SeqAccess<#delife>,
|
} else {
|
||||||
{
|
quote!(mut __seq)
|
||||||
#visit_seq
|
};
|
||||||
}
|
|
||||||
}),
|
let visit_seq = Stmts(deserialize_seq(
|
||||||
|
&type_path, params, fields, true, cattrs, expecting,
|
||||||
|
));
|
||||||
|
|
||||||
|
Some(quote! {
|
||||||
|
#[inline]
|
||||||
|
fn visit_seq<__A>(self, #mut_seq: __A) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||||
|
where
|
||||||
|
__A: _serde::de::SeqAccess<#delife>,
|
||||||
|
{
|
||||||
|
#visit_seq
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user