diff --git a/ruma-events-macros/src/collection.rs b/ruma-events-macros/src/content_enum.rs similarity index 89% rename from ruma-events-macros/src/collection.rs rename to ruma-events-macros/src/content_enum.rs index 7a46e544..38fa50a7 100644 --- a/ruma-events-macros/src/collection.rs +++ b/ruma-events-macros/src/content_enum.rs @@ -1,10 +1,10 @@ -//! Implementation of the collection type macro. +//! Implementation of the content_enum type macro. use proc_macro2::TokenStream; use quote::quote; use syn::{Ident, LitStr}; -use parse::RumaCollectionInput; +use parse::ContentEnumInput; fn marker_traits(ident: &Ident) -> TokenStream { match ident.to_string().as_str() { @@ -20,8 +20,8 @@ fn marker_traits(ident: &Ident) -> TokenStream { } } -/// Create a collection from `RumaCollectionInput. -pub fn expand_collection(input: RumaCollectionInput) -> syn::Result { +/// Create a content enum from `ContentEnumInput`. +pub fn expand_content_enum(input: ContentEnumInput) -> syn::Result { let attrs = &input.attrs; let ident = &input.name; let event_type_str = &input.events; @@ -33,7 +33,7 @@ pub fn expand_collection(input: RumaCollectionInput) -> syn::Result .map(to_event_content_path) .collect::>(); - let collection = quote! { + let content_enum = quote! { #( #attrs )* #[derive(Clone, Debug, ::serde::Serialize)] #[serde(untagged)] @@ -71,7 +71,7 @@ pub fn expand_collection(input: RumaCollectionInput) -> syn::Result let marker_trait_impls = marker_traits(ident); Ok(quote! { - #collection + #content_enum #event_content_impl @@ -115,21 +115,21 @@ pub(crate) fn to_camel_case(name: &LitStr) -> Ident { Ident::new(&s, span) } -/// Details of parsing input for the `event_content_collection` procedural macro. +/// Details of parsing input for the `event_content_content_enum` procedural macro. pub mod parse { use syn::{ parse::{self, Parse, ParseStream}, Attribute, Expr, ExprLit, Ident, Lit, LitStr, Token, }; - /// Custom keywords for the `event_content_collection!` macro + /// Custom keywords for the `event_content_content_enum!` macro mod kw { syn::custom_keyword!(name); syn::custom_keyword!(events); } - /// The entire `event_content_collection!` macro structure directly as it appears in the source code.. - pub struct RumaCollectionInput { + /// The entire `event_content_content_enum!` macro structure directly as it appears in the source code.. + pub struct ContentEnumInput { /// Outer attributes on the field, such as a docstring. pub attrs: Vec, @@ -143,13 +143,13 @@ pub mod parse { pub events: Vec, } - impl Parse for RumaCollectionInput { + impl Parse for ContentEnumInput { fn parse(input: ParseStream<'_>) -> parse::Result { let attrs = input.call(Attribute::parse_outer)?; // name field input.parse::()?; input.parse::()?; - // the name of our collection enum + // the name of our content_enum enum let name: Ident = input.parse()?; input.parse::()?; diff --git a/ruma-events-macros/src/lib.rs b/ruma-events-macros/src/lib.rs index 3e2a143d..fc0d2ad7 100644 --- a/ruma-events-macros/src/lib.rs +++ b/ruma-events-macros/src/lib.rs @@ -15,7 +15,7 @@ use quote::ToTokens; use syn::{parse_macro_input, DeriveInput}; use self::{ - collection::{expand_collection, parse::RumaCollectionInput}, + content_enum::{expand_content_enum, parse::ContentEnumInput}, event::expand_event, event_content::{expand_message_event_content, expand_state_event_content}, from_raw::expand_from_raw, @@ -23,7 +23,7 @@ use self::{ parse::RumaEventInput, }; -mod collection; +mod content_enum; mod event; mod event_content; mod from_raw; @@ -123,14 +123,15 @@ pub fn ruma_event(input: TokenStream) -> TokenStream { ruma_event.into_token_stream().into() } -/// Generates a collection type to represent the various Matrix event types. +/// Generates a content enum to represent the various Matrix event types. /// -/// This macro also implements the necessary traits for the type to serialize and deserialize itself. +/// This macro also implements the necessary traits for the type to serialize and deserialize +/// itself. // TODO more docs/example #[proc_macro] -pub fn event_content_collection(input: TokenStream) -> TokenStream { - let ruma_collection_input = syn::parse_macro_input!(input as RumaCollectionInput); - expand_collection(ruma_collection_input) +pub fn event_content_enum(input: TokenStream) -> TokenStream { + let content_enum_input = syn::parse_macro_input!(input as ContentEnumInput); + expand_content_enum(content_enum_input) .unwrap_or_else(|err| err.to_compile_error()) .into() } diff --git a/src/message.rs b/src/message.rs index ba24b12d..ed4f185b 100644 --- a/src/message.rs +++ b/src/message.rs @@ -14,9 +14,9 @@ use serde::{ }; use crate::{MessageEventContent, RoomEventContent, UnsignedData}; -use ruma_events_macros::{event_content_collection, Event}; +use ruma_events_macros::{event_content_enum, Event}; -event_content_collection! { +event_content_enum! { /// A message event. name: AnyMessageEventContent, events: [ diff --git a/src/state.rs b/src/state.rs index b325f990..46ee1062 100644 --- a/src/state.rs +++ b/src/state.rs @@ -14,9 +14,9 @@ use serde::{ }; use crate::{RoomEventContent, StateEventContent, TryFromRaw, UnsignedData}; -use ruma_events_macros::{event_content_collection, Event}; +use ruma_events_macros::{event_content_enum, Event}; -event_content_collection! { +event_content_enum! { /// A state event. name: AnyStateEventContent, events: [