Merge pull request #1227 from serde-rs/ser

Improve Serialize of adjacently tagged newtype variants
This commit is contained in:
David Tolnay 2018-04-21 12:10:28 -07:00 committed by GitHub
commit 1a972d2105
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -596,9 +596,15 @@ fn serialize_adjacently_tagged_variant(
field_expr = wrap_serialize_field_with(params, field.ty, path, &field_expr);
}
quote_expr! {
_serde::Serialize::serialize(#field_expr, __serializer)
}
return quote_block! {
let mut __struct = try!(_serde::Serializer::serialize_struct(
__serializer, #type_name, 2));
try!(_serde::ser::SerializeStruct::serialize_field(
&mut __struct, #tag, #variant_name));
try!(_serde::ser::SerializeStruct::serialize_field(
&mut __struct, #content, #field_expr));
_serde::ser::SerializeStruct::end(__struct)
};
}
Style::Tuple => {
serialize_tuple_variant(TupleVariant::Untagged, params, &variant.fields)