events: Add accessor for AnyFullStateEventContent's event type
This commit is contained in:
parent
baaf73adbc
commit
e4678284ca
@ -439,6 +439,19 @@ where
|
|||||||
Redacted(C::Redacted),
|
Redacted(C::Redacted),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<C: StateEventContent + RedactContent> FullStateEventContent<C>
|
||||||
|
where
|
||||||
|
C::Redacted: RedactedStateEventContent,
|
||||||
|
{
|
||||||
|
/// Get the event’s type, like `m.room.create`.
|
||||||
|
pub fn event_type(&self) -> StateEventType {
|
||||||
|
match self {
|
||||||
|
Self::Original { content, .. } => content.event_type(),
|
||||||
|
Self::Redacted(content) => content.event_type(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! impl_possibly_redacted_event {
|
macro_rules! impl_possibly_redacted_event {
|
||||||
(
|
(
|
||||||
$ty:ident ( $content_trait:ident, $redacted_content_trait:ident, $event_type:ident )
|
$ty:ident ( $content_trait:ident, $redacted_content_trait:ident, $event_type:ident )
|
||||||
|
@ -432,6 +432,8 @@ fn expand_full_content_enum(
|
|||||||
) -> syn::Result<TokenStream> {
|
) -> syn::Result<TokenStream> {
|
||||||
let ident = kind.to_full_content_enum();
|
let ident = kind.to_full_content_enum();
|
||||||
|
|
||||||
|
let event_type_enum = kind.to_event_type_enum();
|
||||||
|
|
||||||
let content: Vec<_> = events
|
let content: Vec<_> = events
|
||||||
.iter()
|
.iter()
|
||||||
.map(|event| {
|
.map(|event| {
|
||||||
@ -441,6 +443,7 @@ fn expand_full_content_enum(
|
|||||||
.collect::<syn::Result<_>>()?;
|
.collect::<syn::Result<_>>()?;
|
||||||
|
|
||||||
let variant_decls = variants.iter().map(|v| v.decl()).collect::<Vec<_>>();
|
let variant_decls = variants.iter().map(|v| v.decl()).collect::<Vec<_>>();
|
||||||
|
let variant_arms = variants.iter().map(|v| v.match_arm(quote! { Self })).collect::<Vec<_>>();
|
||||||
|
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
#( #attrs )*
|
#( #attrs )*
|
||||||
@ -458,6 +461,16 @@ fn expand_full_content_enum(
|
|||||||
redacted: bool,
|
redacted: bool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl #ident {
|
||||||
|
/// Get the event’s type, like `m.room.create`.
|
||||||
|
pub fn event_type(&self) -> #ruma_common::events::#event_type_enum {
|
||||||
|
match self {
|
||||||
|
#( #variant_arms(content) => content.event_type(), )*
|
||||||
|
Self::_Custom { event_type, .. } => ::std::convert::From::from(&event_type.0[..]),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user