Add event_type
accessor method to event enums
This commit is contained in:
parent
ed6e55a22f
commit
6bbb42303b
@ -711,6 +711,18 @@ fn accessor_methods(
|
||||
let self_variants: Vec<_> = variants.iter().map(|v| v.match_arm(quote!(Self))).collect();
|
||||
let content_variants: Vec<_> = variants.iter().map(|v| v.ctor(&content_enum)).collect();
|
||||
|
||||
let event_type = quote! {
|
||||
/// Returns the `type` of this event.
|
||||
pub fn event_type(&self) -> &str {
|
||||
match self {
|
||||
#( #self_variants(event) =>
|
||||
#ruma_events::EventContent::event_type(&event.content), )*
|
||||
Self::Custom(event) =>
|
||||
#ruma_events::EventContent::event_type(&event.content),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let content = quote! {
|
||||
/// Returns the any content enum for this event.
|
||||
pub fn content(&self) -> #content_enum {
|
||||
@ -746,6 +758,8 @@ fn accessor_methods(
|
||||
impl #ident {
|
||||
#content
|
||||
|
||||
#event_type
|
||||
|
||||
#prev_content
|
||||
|
||||
#( #methods )*
|
||||
|
@ -269,4 +269,5 @@ fn alias_event_field_access() {
|
||||
} else {
|
||||
panic!("the `Any*Event` enum's accessor methods may have been altered")
|
||||
}
|
||||
assert_eq!(deser.event_type(), "m.room.aliases");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user