Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow enum variants to be serialized as empty tags #3

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions xml_struct_derive/src/serialize/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub(super) fn with_enum_variants(
VariantKind::Struct(fields) => {
let VariantTokenSets {
accessors,
content_calls,
body: content_calls,
} = generate_variant_token_sets(name_tokens, namespace_attrs, fields);

quote! {
Expand All @@ -223,7 +223,7 @@ pub(super) fn with_enum_variants(
VariantKind::Tuple(fields) => {
let VariantTokenSets {
accessors,
content_calls,
body: content_calls,
} = generate_variant_token_sets(name_tokens, namespace_attrs, fields);

quote! {
Expand Down Expand Up @@ -273,7 +273,7 @@ struct VariantTokenSets {

/// The calls for serializing the child nodes of the XML element
/// representing an enum variant.
content_calls: TokenStream,
body: TokenStream,
}

/// Generates a list of accessors and set of calls to serialize content for an
Expand All @@ -294,18 +294,18 @@ fn generate_variant_token_sets(
child_fields,
} = partition_fields(fields);

let child_node_calls = generate_field_content_node_calls(child_fields);
let content_calls = if !child_fields.is_empty() {
Some(generate_field_content_node_calls(child_fields))
} else {
None
};

let content_calls = generate_xml_tag_calls(
name_tokens,
namespace_attrs,
&attr_fields,
Some(child_node_calls),
);
let variant_body =
generate_xml_tag_calls(name_tokens, namespace_attrs, &attr_fields, content_calls);

VariantTokenSets {
accessors,
content_calls,
body: variant_body,
}
}

Expand Down
Loading