Rename event_type when deserializing custom events
This commit is contained in:
parent
c7d7212b00
commit
3128351031
@ -343,11 +343,15 @@ impl ToTokens for RumaEvent {
|
|||||||
TokenStream::new()
|
TokenStream::new()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let stripped_fields = event_fields
|
||||||
|
.iter()
|
||||||
|
.map(|event_field| strip_serde_attrs(event_field));
|
||||||
|
|
||||||
let output = quote!(
|
let output = quote!(
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
#[derive(Clone, PartialEq, Debug)]
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
pub struct #name {
|
pub struct #name {
|
||||||
#(#event_fields),*
|
#(#stripped_fields),*
|
||||||
}
|
}
|
||||||
|
|
||||||
#content
|
#content
|
||||||
@ -431,6 +435,7 @@ fn populate_event_fields(
|
|||||||
pub content: #content_name,
|
pub content: #content_name,
|
||||||
|
|
||||||
/// The custom type of the event.
|
/// The custom type of the event.
|
||||||
|
#[serde(rename = "type")]
|
||||||
pub event_type: String,
|
pub event_type: String,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -523,3 +528,10 @@ impl Parse for ParsableNamedField {
|
|||||||
Ok(Self { field })
|
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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user