events: Skip serialization of all None
event fields
… not just prev_content.
This commit is contained in:
parent
4e2b93617a
commit
0890c3c37c
@ -76,12 +76,6 @@ fn expand_serialize_event(
|
||||
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" {
|
||||
quote! {
|
||||
if !self.unsigned.is_empty() {
|
||||
@ -89,8 +83,20 @@ fn expand_serialize_event(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let name_s = name.to_string();
|
||||
match &field.ty {
|
||||
syn::Type::Path(syn::TypePath { path: syn::Path { segments, .. }, .. })
|
||||
if segments.last().unwrap().ident == "Option" =>
|
||||
{
|
||||
quote! {
|
||||
state.serialize_field(stringify!(#name), &self.#name)?;
|
||||
if let Some(content) = self.#name.as_ref() {
|
||||
state.serialize_field(#name_s, content)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => quote! {
|
||||
state.serialize_field(#name_s, &self.#name)?;
|
||||
},
|
||||
}
|
||||
}
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user