events: Generate more event type aliases

This commit is contained in:
Jonas Platte 2021-09-30 20:11:32 +02:00
parent ddda5c0ef3
commit bb581e9252
No known key found for this signature in database
GPG Key ID: 7D261D771D915378

View File

@ -338,30 +338,38 @@ fn generate_event_type_aliases(
syn::Error::new_spanned(ident, "Expected content struct name ending in `Content`") syn::Error::new_spanned(ident, "Expected content struct name ending in `Content`")
})?; })?;
let ev_type = format_ident!("{}", ev_type_s); let type_aliases = [
let ev_type_doc = EventKindVariation::Full,
format!("A `{}` event.\n\nFor more information, see [`{}`].", event_type, ident); EventKindVariation::Sync,
let ev_struct = format_ident!("{}", event_kind); EventKindVariation::Stripped,
EventKindVariation::Redacted,
EventKindVariation::RedactedSync,
]
.iter()
.filter_map(|kind| Some((kind, event_kind.to_event_ident(kind)?)))
.map(|(kind, ev_struct)| {
let ev_type = format_ident!("{}{}", kind, ev_type_s);
let sync_type_alias = let doc_text = match kind {
event_kind.to_event_ident(&EventKindVariation::Sync).map(|sync_ev_struct| { EventKindVariation::Full => "",
let sync_ev_type = format_ident!("Sync{}", ev_type_s); EventKindVariation::Sync => " from a `sync_events` response",
let sync_ev_type_doc = format!( EventKindVariation::Stripped => " from an invited room preview",
"A `{}` event from a `sync_events` response.\n\nFor more information, see [`{}`].", EventKindVariation::Redacted => " that has been redacted",
event_type, ident, EventKindVariation::RedactedSync => {
); "from a `sync_events` response that has been redacted"
}
EventKindVariation::Initial => unreachable!(),
};
let ev_type_doc = format!("An `{}` event{}.", event_type, doc_text);
quote! { quote! {
#[doc = #sync_ev_type_doc]
pub type #sync_ev_type = #ruma_events::#sync_ev_struct<#ident>;
}
});
Ok(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<#ident>;
#sync_type_alias }
}) })
.collect();
Ok(type_aliases)
} }
fn generate_marker_trait_impl( fn generate_marker_trait_impl(