mirror of
https://github.com/serde-rs/serde.git
synced 2025-09-27 13:00:49 +00:00
Move code for injecting tagged variants to untagged generator to the place where the decision was made
This commit is contained in:
parent
6dffc0b1c8
commit
4855fb467f
@ -1228,6 +1228,14 @@ fn deserialize_enum(
|
|||||||
Some(variant_idx) => {
|
Some(variant_idx) => {
|
||||||
let (tagged, untagged) = variants.split_at(variant_idx);
|
let (tagged, untagged) = variants.split_at(variant_idx);
|
||||||
let tagged_frag = Expr(deserialize_homogeneous_enum(params, tagged, cattrs));
|
let tagged_frag = Expr(deserialize_homogeneous_enum(params, tagged, cattrs));
|
||||||
|
// Ignore any error associated with non-untagged deserialization so that we
|
||||||
|
// can fall through to the untagged variants. This may be infallible so we
|
||||||
|
// need to provide the error type.
|
||||||
|
let tagged_frag = quote! {
|
||||||
|
if let _serde::#private::Result::<_, __D::Error>::Ok(__ok) = (|| #tagged_frag)() {
|
||||||
|
return _serde::#private::Ok(__ok);
|
||||||
|
}
|
||||||
|
};
|
||||||
deserialize_untagged_enum(params, untagged, cattrs, Some(tagged_frag))
|
deserialize_untagged_enum(params, untagged, cattrs, Some(tagged_frag))
|
||||||
}
|
}
|
||||||
None => deserialize_homogeneous_enum(params, variants, cattrs),
|
None => deserialize_homogeneous_enum(params, variants, cattrs),
|
||||||
@ -1753,7 +1761,7 @@ fn deserialize_untagged_enum(
|
|||||||
params: &Parameters,
|
params: &Parameters,
|
||||||
variants: &[Variant],
|
variants: &[Variant],
|
||||||
cattrs: &attr::Container,
|
cattrs: &attr::Container,
|
||||||
first_attempt: Option<Expr>,
|
first_attempt: Option<TokenStream>,
|
||||||
) -> Fragment {
|
) -> Fragment {
|
||||||
let attempts = variants
|
let attempts = variants
|
||||||
.iter()
|
.iter()
|
||||||
@ -1778,17 +1786,6 @@ fn deserialize_untagged_enum(
|
|||||||
);
|
);
|
||||||
let fallthrough_msg = cattrs.expecting().unwrap_or(&fallthrough_msg);
|
let fallthrough_msg = cattrs.expecting().unwrap_or(&fallthrough_msg);
|
||||||
|
|
||||||
// Ignore any error associated with non-untagged deserialization so that we
|
|
||||||
// can fall through to the untagged variants. This may be infallible so we
|
|
||||||
// need to provide the error type.
|
|
||||||
let first_attempt = first_attempt.map(|expr| {
|
|
||||||
quote! {
|
|
||||||
if let _serde::#private::Result::<_, __D::Error>::Ok(__ok) = (|| #expr)() {
|
|
||||||
return _serde::#private::Ok(__ok);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let private2 = private;
|
let private2 = private;
|
||||||
quote_block! {
|
quote_block! {
|
||||||
let __content = _serde::de::DeserializeSeed::deserialize(_serde::#private::de::ContentVisitor::new(), __deserializer)?;
|
let __content = _serde::de::DeserializeSeed::deserialize(_serde::#private::de::ContentVisitor::new(), __deserializer)?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user