Inline AdjacentlyTaggedEnumVariant::new

This commit is contained in:
David Tolnay 2023-08-01 22:10:16 -07:00
parent 5cdd82d41e
commit 9bd52ec5c1
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 13 additions and 17 deletions

View File

@ -1357,19 +1357,9 @@ where
} }
pub struct AdjacentlyTaggedEnumVariant { pub struct AdjacentlyTaggedEnumVariant {
tag: &'static str, pub tag: &'static str,
variant_index: u32, pub variant_index: u32,
variant_name: &'static str, pub 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,
}
}
} }
impl Serialize for AdjacentlyTaggedEnumVariant { impl Serialize for AdjacentlyTaggedEnumVariant {

View File

@ -648,7 +648,13 @@ fn serialize_adjacently_tagged_variant(
let this_type = &params.this_type; let this_type = &params.this_type;
let type_name = cattrs.name().serialize_name(); let type_name = cattrs.name().serialize_name();
let variant_name = variant.attrs.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 inner = Stmts(if let Some(path) = variant.attrs.serialize_with() {
let ser = wrap_serialize_variant_with(params, path, variant); 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( let mut __struct = _serde::Serializer::serialize_struct(
__serializer, #type_name, 1)?; __serializer, #type_name, 1)?;
_serde::ser::SerializeStruct::serialize_field( _serde::ser::SerializeStruct::serialize_field(
&mut __struct, #tag, #variant)?; &mut __struct, #tag, #serialize_variant)?;
_serde::ser::SerializeStruct::end(__struct) _serde::ser::SerializeStruct::end(__struct)
}; };
} }
@ -679,7 +685,7 @@ fn serialize_adjacently_tagged_variant(
let mut __struct = _serde::Serializer::serialize_struct( let mut __struct = _serde::Serializer::serialize_struct(
__serializer, #type_name, 2)?; __serializer, #type_name, 2)?;
_serde::ser::SerializeStruct::serialize_field( _serde::ser::SerializeStruct::serialize_field(
&mut __struct, #tag, #variant)?; &mut __struct, #tag, #serialize_variant)?;
#func( #func(
&mut __struct, #content, #field_expr)?; &mut __struct, #content, #field_expr)?;
_serde::ser::SerializeStruct::end(__struct) _serde::ser::SerializeStruct::end(__struct)
@ -744,7 +750,7 @@ fn serialize_adjacently_tagged_variant(
let mut __struct = _serde::Serializer::serialize_struct( let mut __struct = _serde::Serializer::serialize_struct(
__serializer, #type_name, 2)?; __serializer, #type_name, 2)?;
_serde::ser::SerializeStruct::serialize_field( _serde::ser::SerializeStruct::serialize_field(
&mut __struct, #tag, #variant)?; &mut __struct, #tag, #serialize_variant)?;
_serde::ser::SerializeStruct::serialize_field( _serde::ser::SerializeStruct::serialize_field(
&mut __struct, #content, &__AdjacentlyTagged { &mut __struct, #content, &__AdjacentlyTagged {
data: (#(#fields_ident,)*), data: (#(#fields_ident,)*),