diff --git a/serde/src/private/ser.rs b/serde/src/private/ser.rs index 87ced064e..7a801c9d3 100644 --- a/serde/src/private/ser.rs +++ b/serde/src/private/ser.rs @@ -1357,19 +1357,9 @@ where } pub struct AdjacentlyTaggedEnumVariant { - tag: &'static str, - variant_index: u32, - variant_name: &'static str, -} - -impl AdjacentlyTaggedEnumVariant { - pub fn new(tag: &'static str, variant_index: u32, variant_name: &'static str) -> Self { - AdjacentlyTaggedEnumVariant { - tag, - variant_index, - variant_name, - } - } + pub tag: &'static str, + pub variant_index: u32, + pub variant_name: &'static str, } impl Serialize for AdjacentlyTaggedEnumVariant { diff --git a/serde_derive/src/ser.rs b/serde_derive/src/ser.rs index e501e2d0f..8a0f58dde 100644 --- a/serde_derive/src/ser.rs +++ b/serde_derive/src/ser.rs @@ -648,7 +648,13 @@ fn serialize_adjacently_tagged_variant( let this_type = ¶ms.this_type; let type_name = cattrs.name().serialize_name(); let variant_name = variant.attrs.name().serialize_name(); - let variant = quote!(&_serde::__private::ser::AdjacentlyTaggedEnumVariant::new(#tag, #variant_index, #variant_name)); + let serialize_variant = quote! { + &_serde::__private::ser::AdjacentlyTaggedEnumVariant { + tag: #tag, + variant_index: #variant_index, + variant_name: #variant_name, + } + }; let inner = Stmts(if let Some(path) = variant.attrs.serialize_with() { let ser = wrap_serialize_variant_with(params, path, variant); @@ -662,7 +668,7 @@ fn serialize_adjacently_tagged_variant( let mut __struct = _serde::Serializer::serialize_struct( __serializer, #type_name, 1)?; _serde::ser::SerializeStruct::serialize_field( - &mut __struct, #tag, #variant)?; + &mut __struct, #tag, #serialize_variant)?; _serde::ser::SerializeStruct::end(__struct) }; } @@ -679,7 +685,7 @@ fn serialize_adjacently_tagged_variant( let mut __struct = _serde::Serializer::serialize_struct( __serializer, #type_name, 2)?; _serde::ser::SerializeStruct::serialize_field( - &mut __struct, #tag, #variant)?; + &mut __struct, #tag, #serialize_variant)?; #func( &mut __struct, #content, #field_expr)?; _serde::ser::SerializeStruct::end(__struct) @@ -744,7 +750,7 @@ fn serialize_adjacently_tagged_variant( let mut __struct = _serde::Serializer::serialize_struct( __serializer, #type_name, 2)?; _serde::ser::SerializeStruct::serialize_field( - &mut __struct, #tag, #variant)?; + &mut __struct, #tag, #serialize_variant)?; _serde::ser::SerializeStruct::serialize_field( &mut __struct, #content, &__AdjacentlyTagged { data: (#(#fields_ident,)*),