events: Fix redacted event type aliases

This commit is contained in:
Jonas Platte 2021-10-01 18:41:11 +02:00
parent edbd5a696c
commit 802c83f38b
No known key found for this signature in database
GPG Key ID: 7D261D771D915378

View File

@ -1,5 +1,7 @@
//! Implementations of the MessageEventContent and StateEventContent derive macro. //! Implementations of the MessageEventContent and StateEventContent derive macro.
use std::borrow::Cow;
use proc_macro2::{Span, TokenStream}; use proc_macro2::{Span, TokenStream};
use quote::{format_ident, quote}; use quote::{format_ident, quote};
use syn::{ use syn::{
@ -362,9 +364,15 @@ fn generate_event_type_aliases(
}; };
let ev_type_doc = format!("An `{}` event{}.", event_type, doc_text); let ev_type_doc = format!("An `{}` event{}.", event_type, doc_text);
let content_struct = if kind.is_redacted() {
Cow::Owned(format_ident!("Redacted{}", ident))
} else {
Cow::Borrowed(ident)
};
quote! { quote! {
#[doc = #ev_type_doc] #[doc = #ev_type_doc]
pub type #ev_type = #ruma_events::#ev_struct<#ident>; pub type #ev_type = #ruma_events::#ev_struct<#content_struct>;
} }
}) })
.collect(); .collect();