Skip to content

Commit

Permalink
Add support for internally tagged enums in non self-describing formats
Browse files Browse the repository at this point in the history
Deserializer methods are only hints which deserializer is not obliged to follow.
Both TaggedContentVisitor and InternallyTaggedUnitVisitor accepts only
visit_map and visit_seq and that is what derived implementation of Deserialize
does for structs. Therefore it is fine to call deserialize_map here, as that
already did in derived deserialize implementation
  • Loading branch information
Mingun committed Aug 12, 2023
1 parent 1006028 commit dafede9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions serde_derive/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ fn deserialize_struct(
_serde::de::VariantAccess::struct_variant(__variant, FIELDS, #visitor_expr)
},
StructForm::InternallyTagged(_, deserializer) => quote! {
_serde::Deserializer::deserialize_any(#deserializer, #visitor_expr)
_serde::Deserializer::deserialize_map(#deserializer, #visitor_expr)
},
StructForm::Untagged(_, deserializer) => quote! {
_serde::Deserializer::deserialize_any(#deserializer, #visitor_expr)
Expand Down Expand Up @@ -1392,7 +1392,7 @@ fn deserialize_internally_tagged_enum(

#variants_stmt

let (__tag, __content) = _serde::Deserializer::deserialize_any(
let (__tag, __content) = _serde::Deserializer::deserialize_map(
__deserializer,
_serde::__private::de::TaggedContentVisitor::<__Field>::new(#tag, #expecting))?;
let __deserializer = _serde::__private::de::ContentDeserializer::<__D::Error>::new(__content);
Expand Down Expand Up @@ -1840,7 +1840,7 @@ fn deserialize_internally_tagged_variant(
quote!((#default))
});
quote_block! {
_serde::Deserializer::deserialize_any(#deserializer, _serde::__private::de::InternallyTaggedUnitVisitor::new(#type_name, #variant_name))?;
_serde::Deserializer::deserialize_map(#deserializer, _serde::__private::de::InternallyTaggedUnitVisitor::new(#type_name, #variant_name))?;
_serde::__private::Ok(#this_value::#variant_ident #default)
}
}
Expand Down

0 comments on commit dafede9

Please sign in to comment.