mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-12 23:41:03 +00:00
Factor skipping in newtype variants into effective_style
This commit is contained in:
+11
-37
@@ -509,7 +509,7 @@ fn serialize_externally_tagged_variant(
|
||||
};
|
||||
}
|
||||
|
||||
match variant.style {
|
||||
match effective_style(variant) {
|
||||
Style::Unit => {
|
||||
quote_expr! {
|
||||
_serde::Serializer::serialize_unit_variant(
|
||||
@@ -522,16 +522,6 @@ fn serialize_externally_tagged_variant(
|
||||
}
|
||||
Style::Newtype => {
|
||||
let field = &variant.fields[0];
|
||||
if field.attrs.skip_serializing() {
|
||||
return quote_expr! {
|
||||
_serde::Serializer::serialize_unit_variant(
|
||||
__serializer,
|
||||
#type_name,
|
||||
#variant_index,
|
||||
#variant_name,
|
||||
)
|
||||
};
|
||||
}
|
||||
let mut field_expr = quote!(__field0);
|
||||
if let Some(path) = field.attrs.serialize_with() {
|
||||
field_expr = wrap_serialize_field_with(params, field.ty, path, &field_expr);
|
||||
@@ -596,7 +586,7 @@ fn serialize_internally_tagged_variant(
|
||||
};
|
||||
}
|
||||
|
||||
match variant.style {
|
||||
match effective_style(variant) {
|
||||
Style::Unit => {
|
||||
quote_block! {
|
||||
let mut __struct = try!(_serde::Serializer::serialize_struct(
|
||||
@@ -608,15 +598,6 @@ fn serialize_internally_tagged_variant(
|
||||
}
|
||||
Style::Newtype => {
|
||||
let field = &variant.fields[0];
|
||||
if field.attrs.skip_serializing() {
|
||||
return quote_block! {
|
||||
let mut __struct = try!(_serde::Serializer::serialize_struct(
|
||||
__serializer, #type_name, 1));
|
||||
try!(_serde::ser::SerializeStruct::serialize_field(
|
||||
&mut __struct, #tag, #variant_name));
|
||||
_serde::ser::SerializeStruct::end(__struct)
|
||||
};
|
||||
}
|
||||
let mut field_expr = quote!(__field0);
|
||||
if let Some(path) = field.attrs.serialize_with() {
|
||||
field_expr = wrap_serialize_field_with(params, field.ty, path, &field_expr);
|
||||
@@ -665,7 +646,7 @@ fn serialize_adjacently_tagged_variant(
|
||||
_serde::Serialize::serialize(#ser, __serializer)
|
||||
}
|
||||
} else {
|
||||
match variant.style {
|
||||
match effective_style(variant) {
|
||||
Style::Unit => {
|
||||
return quote_block! {
|
||||
let mut __struct = try!(_serde::Serializer::serialize_struct(
|
||||
@@ -677,15 +658,6 @@ fn serialize_adjacently_tagged_variant(
|
||||
}
|
||||
Style::Newtype => {
|
||||
let field = &variant.fields[0];
|
||||
if field.attrs.skip_serializing() {
|
||||
return quote_block! {
|
||||
let mut __struct = try!(_serde::Serializer::serialize_struct(
|
||||
__serializer, #type_name, 1));
|
||||
try!(_serde::ser::SerializeStruct::serialize_field(
|
||||
&mut __struct, #tag, #variant_name));
|
||||
_serde::ser::SerializeStruct::end(__struct)
|
||||
};
|
||||
}
|
||||
let mut field_expr = quote!(__field0);
|
||||
if let Some(path) = field.attrs.serialize_with() {
|
||||
field_expr = wrap_serialize_field_with(params, field.ty, path, &field_expr);
|
||||
@@ -781,7 +753,7 @@ fn serialize_untagged_variant(
|
||||
};
|
||||
}
|
||||
|
||||
match variant.style {
|
||||
match effective_style(variant) {
|
||||
Style::Unit => {
|
||||
quote_expr! {
|
||||
_serde::Serializer::serialize_unit(__serializer)
|
||||
@@ -789,11 +761,6 @@ fn serialize_untagged_variant(
|
||||
}
|
||||
Style::Newtype => {
|
||||
let field = &variant.fields[0];
|
||||
if field.attrs.skip_serializing() {
|
||||
return quote_expr! {
|
||||
_serde::Serializer::serialize_unit(__serializer)
|
||||
};
|
||||
}
|
||||
let mut field_expr = quote!(__field0);
|
||||
if let Some(path) = field.attrs.serialize_with() {
|
||||
field_expr = wrap_serialize_field_with(params, field.ty, path, &field_expr);
|
||||
@@ -1291,6 +1258,13 @@ fn get_member(params: &Parameters, field: &Field, member: &Member) -> TokenStrea
|
||||
}
|
||||
}
|
||||
|
||||
fn effective_style(variant: &Variant) -> Style {
|
||||
match variant.style {
|
||||
Style::Newtype if variant.fields[0].attrs.skip_serializing() => Style::Unit,
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
|
||||
enum StructTrait {
|
||||
SerializeMap,
|
||||
SerializeStruct,
|
||||
|
||||
Reference in New Issue
Block a user