Skip to content

Commit

Permalink
Inline AdjacentlyTaggedEnumVariant::new
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Aug 2, 2023
1 parent 5cdd82d commit 9bd52ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
16 changes: 3 additions & 13 deletions serde/src/private/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 10 additions & 4 deletions serde_derive/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,13 @@ fn serialize_adjacently_tagged_variant(
let this_type = &params.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);
Expand All @@ -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)
};
}
Expand All @@ -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)
Expand Down Expand Up @@ -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,)*),
Expand Down

0 comments on commit 9bd52ec

Please sign in to comment.