Move generiс code out-of-function, create more specialized and simple code
This commit is contained in:
parent
2a36d11238
commit
5e313a7330
@ -1247,11 +1247,20 @@ fn prepare_enum_variant_enum(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let (ignore_variant, fallthrough) = if let Some(other_idx) = other_idx {
|
||||||
|
let ignore_variant = variant_names_idents[other_idx].1.clone();
|
||||||
|
let fallthrough = quote!(_serde::__private::Ok(__Field::#ignore_variant));
|
||||||
|
(None, Some(fallthrough))
|
||||||
|
} else {
|
||||||
|
(None, None)
|
||||||
|
};
|
||||||
|
|
||||||
let variant_visitor = Stmts(deserialize_generated_identifier(
|
let variant_visitor = Stmts(deserialize_generated_identifier(
|
||||||
&variant_names_idents,
|
&variant_names_idents,
|
||||||
cattrs,
|
cattrs,
|
||||||
true,
|
true,
|
||||||
other_idx,
|
ignore_variant,
|
||||||
|
fallthrough,
|
||||||
));
|
));
|
||||||
|
|
||||||
(variants_stmt, variant_visitor)
|
(variants_stmt, variant_visitor)
|
||||||
@ -1976,27 +1985,12 @@ fn deserialize_generated_identifier(
|
|||||||
fields: &[(&str, Ident, &BTreeSet<String>)],
|
fields: &[(&str, Ident, &BTreeSet<String>)],
|
||||||
cattrs: &attr::Container,
|
cattrs: &attr::Container,
|
||||||
is_variant: bool,
|
is_variant: bool,
|
||||||
other_idx: Option<usize>,
|
ignore_variant: Option<TokenStream>,
|
||||||
|
fallthrough: Option<TokenStream>,
|
||||||
) -> Fragment {
|
) -> Fragment {
|
||||||
let this_value = quote!(__Field);
|
let this_value = quote!(__Field);
|
||||||
let field_idents: &Vec<_> = &fields.iter().map(|(_, ident, _)| ident).collect();
|
let field_idents: &Vec<_> = &fields.iter().map(|(_, ident, _)| ident).collect();
|
||||||
|
|
||||||
let (ignore_variant, fallthrough) = if !is_variant && cattrs.has_flatten() {
|
|
||||||
let ignore_variant = quote!(__other(_serde::__private::de::Content<'de>),);
|
|
||||||
let fallthrough = quote!(_serde::__private::Ok(__Field::__other(__value)));
|
|
||||||
(Some(ignore_variant), Some(fallthrough))
|
|
||||||
} else if let Some(other_idx) = other_idx {
|
|
||||||
let ignore_variant = fields[other_idx].1.clone();
|
|
||||||
let fallthrough = quote!(_serde::__private::Ok(__Field::#ignore_variant));
|
|
||||||
(None, Some(fallthrough))
|
|
||||||
} else if is_variant || cattrs.deny_unknown_fields() {
|
|
||||||
(None, None)
|
|
||||||
} else {
|
|
||||||
let ignore_variant = quote!(__ignore,);
|
|
||||||
let fallthrough = quote!(_serde::__private::Ok(__Field::__ignore));
|
|
||||||
(Some(ignore_variant), Some(fallthrough))
|
|
||||||
};
|
|
||||||
|
|
||||||
let visitor_impl = Stmts(deserialize_identifier(
|
let visitor_impl = Stmts(deserialize_identifier(
|
||||||
&this_value,
|
&this_value,
|
||||||
fields,
|
fields,
|
||||||
@ -2048,11 +2042,24 @@ fn deserialize_field_identifier(
|
|||||||
fields: &[(&str, Ident, &BTreeSet<String>)],
|
fields: &[(&str, Ident, &BTreeSet<String>)],
|
||||||
cattrs: &attr::Container,
|
cattrs: &attr::Container,
|
||||||
) -> Stmts {
|
) -> Stmts {
|
||||||
|
let (ignore_variant, fallthrough) = if cattrs.has_flatten() {
|
||||||
|
let ignore_variant = quote!(__other(_serde::__private::de::Content<'de>),);
|
||||||
|
let fallthrough = quote!(_serde::__private::Ok(__Field::__other(__value)));
|
||||||
|
(Some(ignore_variant), Some(fallthrough))
|
||||||
|
} else if cattrs.deny_unknown_fields() {
|
||||||
|
(None, None)
|
||||||
|
} else {
|
||||||
|
let ignore_variant = quote!(__ignore,);
|
||||||
|
let fallthrough = quote!(_serde::__private::Ok(__Field::__ignore));
|
||||||
|
(Some(ignore_variant), Some(fallthrough))
|
||||||
|
};
|
||||||
|
|
||||||
Stmts(deserialize_generated_identifier(
|
Stmts(deserialize_generated_identifier(
|
||||||
fields,
|
fields,
|
||||||
cattrs,
|
cattrs,
|
||||||
false,
|
false,
|
||||||
None,
|
ignore_variant,
|
||||||
|
fallthrough,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user