Rename event_type when deserializing custom events

This commit is contained in:
stoically 2020-01-01 20:20:13 +01:00
parent c7d7212b00
commit 3128351031
No known key found for this signature in database
GPG Key ID: 3026ED2F90EE0DE9

View File

@ -343,11 +343,15 @@ impl ToTokens for RumaEvent {
TokenStream::new()
};
let stripped_fields = event_fields
.iter()
.map(|event_field| strip_serde_attrs(event_field));
let output = quote!(
#(#attrs)*
#[derive(Clone, PartialEq, Debug)]
pub struct #name {
#(#event_fields),*
#(#stripped_fields),*
}
#content
@ -431,6 +435,7 @@ fn populate_event_fields(
pub content: #content_name,
/// The custom type of the event.
#[serde(rename = "type")]
pub event_type: String,
}
} else {
@ -523,3 +528,10 @@ impl Parse for ParsableNamedField {
Ok(Self { field })
}
}
/// Removes `serde` attributes from struct fields.
pub fn strip_serde_attrs(field: &Field) -> Field {
let mut field = field.clone();
field.attrs.retain(|attr| !attr.path.is_ident("serde"));
field
}