events: Skip serialization of all None event fields

… not just prev_content.
This commit is contained in:
Jonas Platte 2021-10-02 14:17:36 +02:00
parent 4e2b93617a
commit 0890c3c37c
No known key found for this signature in database
GPG Key ID: 7D261D771D915378

View File

@ -76,12 +76,6 @@ fn expand_serialize_event(
state.serialize_field("content", &self.content)?; state.serialize_field("content", &self.content)?;
} }
} }
} else if name == "prev_content" {
quote! {
if let Some(content) = self.prev_content.as_ref() {
state.serialize_field("prev_content", content)?;
}
}
} else if name == "unsigned" { } else if name == "unsigned" {
quote! { quote! {
if !self.unsigned.is_empty() { if !self.unsigned.is_empty() {
@ -89,8 +83,20 @@ fn expand_serialize_event(
} }
} }
} else { } else {
quote! { let name_s = name.to_string();
state.serialize_field(stringify!(#name), &self.#name)?; match &field.ty {
syn::Type::Path(syn::TypePath { path: syn::Path { segments, .. }, .. })
if segments.last().unwrap().ident == "Option" =>
{
quote! {
if let Some(content) = self.#name.as_ref() {
state.serialize_field(#name_s, content)?;
}
}
}
_ => quote! {
state.serialize_field(#name_s, &self.#name)?;
},
} }
} }
}) })