common: Create crate-level macro re-exports module
This commit is contained in:
		
							parent
							
								
									43c47ef676
								
							
						
					
					
						commit
						1192bd1099
					
				| @ -140,19 +140,6 @@ mod enums; | |||||||
| mod event_kinds; | mod event_kinds; | ||||||
| mod unsigned; | mod unsigned; | ||||||
| 
 | 
 | ||||||
| /// Re-exports to allow users to declare their own event types using the
 |  | ||||||
| /// macros used internally.
 |  | ||||||
| ///
 |  | ||||||
| /// It is not considered part of this module's public API.
 |  | ||||||
| #[doc(hidden)] |  | ||||||
| pub mod exports { |  | ||||||
|     pub use crate as ruma_common; |  | ||||||
|     pub use ruma_identifiers; |  | ||||||
|     pub use ruma_serde; |  | ||||||
|     pub use serde; |  | ||||||
|     pub use serde_json; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /// Re-export of all the derives needed to create your own event types.
 | /// Re-export of all the derives needed to create your own event types.
 | ||||||
| pub mod macros { | pub mod macros { | ||||||
|     pub use ruma_macros::{Event, EventContent}; |     pub use ruma_macros::{Event, EventContent}; | ||||||
|  | |||||||
| @ -47,3 +47,14 @@ impl fmt::Debug for PrivOwnedStr { | |||||||
|         self.0.fmt(f) |         self.0.fmt(f) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | /// Re-exports used by macro-generated code.
 | ||||||
|  | ///
 | ||||||
|  | /// It is not considered part of this module's public API.
 | ||||||
|  | #[doc(hidden)] | ||||||
|  | pub mod exports { | ||||||
|  |     pub use ruma_identifiers; | ||||||
|  |     pub use ruma_serde; | ||||||
|  |     pub use serde; | ||||||
|  |     pub use serde_json; | ||||||
|  | } | ||||||
|  | |||||||
| @ -11,11 +11,11 @@ use super::{ | |||||||
|     event_parse::{to_kind_variation, EventKind, EventKindVariation}, |     event_parse::{to_kind_variation, EventKind, EventKindVariation}, | ||||||
|     util::is_non_stripped_room_event, |     util::is_non_stripped_room_event, | ||||||
| }; | }; | ||||||
| use crate::import_ruma_events; | use crate::import_ruma_common; | ||||||
| 
 | 
 | ||||||
| /// Derive `Event` macro code generation.
 | /// Derive `Event` macro code generation.
 | ||||||
| pub fn expand_event(input: DeriveInput) -> syn::Result<TokenStream> { | pub fn expand_event(input: DeriveInput) -> syn::Result<TokenStream> { | ||||||
|     let ruma_events = import_ruma_events(); |     let ruma_common = import_ruma_common(); | ||||||
| 
 | 
 | ||||||
|     let ident = &input.ident; |     let ident = &input.ident; | ||||||
|     let (kind, var) = to_kind_variation(ident).ok_or_else(|| { |     let (kind, var) = to_kind_variation(ident).ok_or_else(|| { | ||||||
| @ -44,17 +44,17 @@ pub fn expand_event(input: DeriveInput) -> syn::Result<TokenStream> { | |||||||
| 
 | 
 | ||||||
|     let mut res = TokenStream::new(); |     let mut res = TokenStream::new(); | ||||||
| 
 | 
 | ||||||
|     res.extend(expand_serialize_event(&input, var, &fields, &ruma_events)); |     res.extend(expand_serialize_event(&input, var, &fields, &ruma_common)); | ||||||
|     res.extend(expand_deserialize_event(&input, kind, var, &fields, &ruma_events)?); |     res.extend(expand_deserialize_event(&input, kind, var, &fields, &ruma_common)?); | ||||||
| 
 | 
 | ||||||
|     if var.is_sync() { |     if var.is_sync() { | ||||||
|         res.extend(expand_sync_from_into_full(&input, kind, var, &fields, &ruma_events)); |         res.extend(expand_sync_from_into_full(&input, kind, var, &fields, &ruma_common)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if matches!(kind, EventKind::MessageLike | EventKind::State) |     if matches!(kind, EventKind::MessageLike | EventKind::State) | ||||||
|         && matches!(var, EventKindVariation::Full | EventKindVariation::Sync) |         && matches!(var, EventKindVariation::Full | EventKindVariation::Sync) | ||||||
|     { |     { | ||||||
|         res.extend(expand_redact_event(&input, kind, var, &fields, &ruma_events)); |         res.extend(expand_redact_event(&input, kind, var, &fields, &ruma_common)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if is_non_stripped_room_event(kind, var) { |     if is_non_stripped_room_event(kind, var) { | ||||||
| @ -68,9 +68,9 @@ fn expand_serialize_event( | |||||||
|     input: &DeriveInput, |     input: &DeriveInput, | ||||||
|     var: EventKindVariation, |     var: EventKindVariation, | ||||||
|     fields: &[Field], |     fields: &[Field], | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
| ) -> TokenStream { | ) -> TokenStream { | ||||||
|     let serde = quote! { #ruma_events::exports::serde }; |     let serde = quote! { #ruma_common::exports::serde }; | ||||||
| 
 | 
 | ||||||
|     let ident = &input.ident; |     let ident = &input.ident; | ||||||
|     let (impl_gen, ty_gen, where_clause) = input.generics.split_for_impl(); |     let (impl_gen, ty_gen, where_clause) = input.generics.split_for_impl(); | ||||||
| @ -80,7 +80,7 @@ fn expand_serialize_event( | |||||||
|             let name = field.ident.as_ref().unwrap(); |             let name = field.ident.as_ref().unwrap(); | ||||||
|             if name == "content" && var.is_redacted() { |             if name == "content" && var.is_redacted() { | ||||||
|                 quote! { |                 quote! { | ||||||
|                     if #ruma_events::RedactedEventContent::has_serialize_fields(&self.content) { |                     if #ruma_common::events::RedactedEventContent::has_serialize_fields(&self.content) { | ||||||
|                         state.serialize_field("content", &self.content)?; |                         state.serialize_field("content", &self.content)?; | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
| @ -119,7 +119,7 @@ fn expand_serialize_event( | |||||||
|             { |             { | ||||||
|                 use #serde::ser::{SerializeStruct as _, Error as _}; |                 use #serde::ser::{SerializeStruct as _, Error as _}; | ||||||
| 
 | 
 | ||||||
|                 let event_type = #ruma_events::EventContent::event_type(&self.content); |                 let event_type = #ruma_common::events::EventContent::event_type(&self.content); | ||||||
| 
 | 
 | ||||||
|                 let mut state = serializer.serialize_struct(stringify!(#ident), 7)?; |                 let mut state = serializer.serialize_struct(stringify!(#ident), 7)?; | ||||||
| 
 | 
 | ||||||
| @ -136,10 +136,10 @@ fn expand_deserialize_event( | |||||||
|     _kind: EventKind, |     _kind: EventKind, | ||||||
|     var: EventKindVariation, |     var: EventKindVariation, | ||||||
|     fields: &[Field], |     fields: &[Field], | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
| ) -> syn::Result<TokenStream> { | ) -> syn::Result<TokenStream> { | ||||||
|     let serde = quote! { #ruma_events::exports::serde }; |     let serde = quote! { #ruma_common::exports::serde }; | ||||||
|     let serde_json = quote! { #ruma_events::exports::serde_json }; |     let serde_json = quote! { #ruma_common::exports::serde_json }; | ||||||
| 
 | 
 | ||||||
|     let ident = &input.ident; |     let ident = &input.ident; | ||||||
|     // we know there is a content field already
 |     // we know there is a content field already
 | ||||||
| @ -180,10 +180,10 @@ fn expand_deserialize_event( | |||||||
|                 if matches!(_kind, EventKind::State) && name == "unsigned" { |                 if matches!(_kind, EventKind::State) && name == "unsigned" { | ||||||
|                     match var { |                     match var { | ||||||
|                         EventKindVariation::Full | EventKindVariation::Sync => { |                         EventKindVariation::Full | EventKindVariation::Sync => { | ||||||
|                             ty = quote! { #ruma_events::UnsignedWithPrevContent }; |                             ty = quote! { #ruma_common::events::UnsignedWithPrevContent }; | ||||||
|                         } |                         } | ||||||
|                         EventKindVariation::Redacted | EventKindVariation::RedactedSync => { |                         EventKindVariation::Redacted | EventKindVariation::RedactedSync => { | ||||||
|                             ty = quote! { #ruma_events::RedactedUnsignedWithPrevContent }; |                             ty = quote! { #ruma_common::events::RedactedUnsignedWithPrevContent }; | ||||||
|                         } |                         } | ||||||
|                         EventKindVariation::Stripped | EventKindVariation::Initial => { |                         EventKindVariation::Stripped | EventKindVariation::Initial => { | ||||||
|                             unreachable!() |                             unreachable!() | ||||||
| @ -204,16 +204,16 @@ fn expand_deserialize_event( | |||||||
|                 if is_generic && var.is_redacted() { |                 if is_generic && var.is_redacted() { | ||||||
|                     quote! { |                     quote! { | ||||||
|                         let content = match C::has_deserialize_fields() { |                         let content = match C::has_deserialize_fields() { | ||||||
|                             #ruma_events::HasDeserializeFields::False => { |                             #ruma_common::events::HasDeserializeFields::False => { | ||||||
|                                 C::empty(&event_type).map_err(A::Error::custom)? |                                 C::empty(&event_type).map_err(A::Error::custom)? | ||||||
|                             }, |                             }, | ||||||
|                             #ruma_events::HasDeserializeFields::True => { |                             #ruma_common::events::HasDeserializeFields::True => { | ||||||
|                                 let json = content.ok_or_else( |                                 let json = content.ok_or_else( | ||||||
|                                     || #serde::de::Error::missing_field("content"), |                                     || #serde::de::Error::missing_field("content"), | ||||||
|                                 )?; |                                 )?; | ||||||
|                                 C::from_parts(&event_type, &json).map_err(A::Error::custom)? |                                 C::from_parts(&event_type, &json).map_err(A::Error::custom)? | ||||||
|                             }, |                             }, | ||||||
|                             #ruma_events::HasDeserializeFields::Optional => { |                             #ruma_common::events::HasDeserializeFields::Optional => { | ||||||
|                                 let json = content.unwrap_or( |                                 let json = content.unwrap_or( | ||||||
|                                     #serde_json::value::RawValue::from_string("{}".to_owned()) |                                     #serde_json::value::RawValue::from_string("{}".to_owned()) | ||||||
|                                         .unwrap() |                                         .unwrap() | ||||||
| @ -412,9 +412,9 @@ fn expand_redact_event( | |||||||
|     kind: EventKind, |     kind: EventKind, | ||||||
|     var: EventKindVariation, |     var: EventKindVariation, | ||||||
|     fields: &[Field], |     fields: &[Field], | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
| ) -> TokenStream { | ) -> TokenStream { | ||||||
|     let ruma_identifiers = quote! { #ruma_events::exports::ruma_identifiers }; |     let ruma_identifiers = quote! { #ruma_common::exports::ruma_identifiers }; | ||||||
| 
 | 
 | ||||||
|     let redacted_type = kind.to_event_ident(var.to_redacted()); |     let redacted_type = kind.to_event_ident(var.to_redacted()); | ||||||
|     let redacted_content_trait = |     let redacted_content_trait = | ||||||
| @ -433,10 +433,10 @@ fn expand_redact_event( | |||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     let where_clause = generics.make_where_clause(); |     let where_clause = generics.make_where_clause(); | ||||||
|     where_clause.predicates.push(parse_quote! { #ty_param: #ruma_events::RedactContent }); |     where_clause.predicates.push(parse_quote! { #ty_param: #ruma_common::events::RedactContent }); | ||||||
|     where_clause.predicates.push(parse_quote! { |     where_clause.predicates.push(parse_quote! { | ||||||
|         <#ty_param as #ruma_events::RedactContent>::Redacted: |         <#ty_param as #ruma_common::events::RedactContent>::Redacted: | ||||||
|             #ruma_events::#redacted_content_trait |             #ruma_common::events::#redacted_content_trait | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     let (impl_generics, ty_gen, where_clause) = generics.split_for_impl(); |     let (impl_generics, ty_gen, where_clause) = generics.split_for_impl(); | ||||||
| @ -448,8 +448,9 @@ fn expand_redact_event( | |||||||
|             None |             None | ||||||
|         } else if ident == "unsigned" { |         } else if ident == "unsigned" { | ||||||
|             Some(quote! { |             Some(quote! { | ||||||
|                 unsigned: |                 unsigned: #ruma_common::events::RedactedUnsigned::new_because( | ||||||
|                     #ruma_events::RedactedUnsigned::new_because(::std::boxed::Box::new(redaction)) |                     ::std::boxed::Box::new(redaction), | ||||||
|  |                 ) | ||||||
|             }) |             }) | ||||||
|         } else { |         } else { | ||||||
|             Some(quote! { |             Some(quote! { | ||||||
| @ -460,17 +461,18 @@ fn expand_redact_event( | |||||||
| 
 | 
 | ||||||
|     quote! { |     quote! { | ||||||
|         #[automatically_derived] |         #[automatically_derived] | ||||||
|         impl #impl_generics #ruma_events::Redact for #ident #ty_gen #where_clause { |         impl #impl_generics #ruma_common::events::Redact for #ident #ty_gen #where_clause { | ||||||
|             type Redacted = |             type Redacted = #ruma_common::events::#redacted_type< | ||||||
|                 #ruma_events::#redacted_type<<#ty_param as #ruma_events::RedactContent>::Redacted>; |                 <#ty_param as #ruma_common::events::RedactContent>::Redacted, | ||||||
|  |             >; | ||||||
| 
 | 
 | ||||||
|             fn redact( |             fn redact( | ||||||
|                 self, |                 self, | ||||||
|                 redaction: #ruma_events::room::redaction::SyncRoomRedactionEvent, |                 redaction: #ruma_common::events::room::redaction::SyncRoomRedactionEvent, | ||||||
|                 version: &#ruma_identifiers::RoomVersionId, |                 version: &#ruma_identifiers::RoomVersionId, | ||||||
|             ) -> Self::Redacted { |             ) -> Self::Redacted { | ||||||
|                 let content = #ruma_events::RedactContent::redact(self.content, version); |                 let content = #ruma_common::events::RedactContent::redact(self.content, version); | ||||||
|                 #ruma_events::#redacted_type { |                 #ruma_common::events::#redacted_type { | ||||||
|                     content, |                     content, | ||||||
|                     #(#fields),* |                     #(#fields),* | ||||||
|                 } |                 } | ||||||
| @ -484,9 +486,9 @@ fn expand_sync_from_into_full( | |||||||
|     kind: EventKind, |     kind: EventKind, | ||||||
|     var: EventKindVariation, |     var: EventKindVariation, | ||||||
|     fields: &[Field], |     fields: &[Field], | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
| ) -> TokenStream { | ) -> TokenStream { | ||||||
|     let ruma_identifiers = quote! { #ruma_events::exports::ruma_identifiers }; |     let ruma_identifiers = quote! { #ruma_common::exports::ruma_identifiers }; | ||||||
| 
 | 
 | ||||||
|     let ident = &input.ident; |     let ident = &input.ident; | ||||||
|     let full_struct = kind.to_event_ident(var.to_full()); |     let full_struct = kind.to_event_ident(var.to_full()); | ||||||
|  | |||||||
| @ -103,7 +103,7 @@ impl Parse for MetaAttrs { | |||||||
| /// Create an `EventContent` implementation for a struct.
 | /// Create an `EventContent` implementation for a struct.
 | ||||||
| pub fn expand_event_content( | pub fn expand_event_content( | ||||||
|     input: &DeriveInput, |     input: &DeriveInput, | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
| ) -> syn::Result<TokenStream> { | ) -> syn::Result<TokenStream> { | ||||||
|     let content_attr = input |     let content_attr = input | ||||||
|         .attrs |         .attrs | ||||||
| @ -147,17 +147,17 @@ pub fn expand_event_content( | |||||||
| 
 | 
 | ||||||
|     // We only generate redacted content structs for state and message-like events
 |     // We only generate redacted content structs for state and message-like events
 | ||||||
|     let redacted_event_content = needs_redacted(&content_attr, event_kind) |     let redacted_event_content = needs_redacted(&content_attr, event_kind) | ||||||
|         .then(|| generate_redacted_event_content(input, event_type, ruma_events, event_kind)) |         .then(|| generate_redacted_event_content(input, event_type, ruma_common, event_kind)) | ||||||
|         .transpose()?; |         .transpose()?; | ||||||
| 
 | 
 | ||||||
|     let event_content_impl = generate_event_content_impl(&input.ident, event_type, ruma_events); |     let event_content_impl = generate_event_content_impl(&input.ident, event_type, ruma_common); | ||||||
|     let static_event_content_impl = event_kind.map(|k| { |     let static_event_content_impl = event_kind.map(|k| { | ||||||
|         generate_static_event_content_impl(&input.ident, k, false, event_type, ruma_events) |         generate_static_event_content_impl(&input.ident, k, false, event_type, ruma_common) | ||||||
|     }); |     }); | ||||||
|     let marker_trait_impl = |     let marker_trait_impl = | ||||||
|         event_kind.map(|k| generate_marker_trait_impl(k, &input.ident, ruma_events)).transpose()?; |         event_kind.map(|k| generate_marker_trait_impl(k, &input.ident, ruma_common)).transpose()?; | ||||||
|     let type_aliases = event_kind |     let type_aliases = event_kind | ||||||
|         .map(|k| generate_event_type_aliases(k, &input.ident, &event_type.value(), ruma_events)) |         .map(|k| generate_event_type_aliases(k, &input.ident, &event_type.value(), ruma_common)) | ||||||
|         .transpose()?; |         .transpose()?; | ||||||
| 
 | 
 | ||||||
|     Ok(quote! { |     Ok(quote! { | ||||||
| @ -172,12 +172,12 @@ pub fn expand_event_content( | |||||||
| fn generate_redacted_event_content( | fn generate_redacted_event_content( | ||||||
|     input: &DeriveInput, |     input: &DeriveInput, | ||||||
|     event_type: &LitStr, |     event_type: &LitStr, | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
|     event_kind: Option<EventKind>, |     event_kind: Option<EventKind>, | ||||||
| ) -> Result<TokenStream, syn::Error> { | ) -> Result<TokenStream, syn::Error> { | ||||||
|     let ruma_identifiers = quote! { #ruma_events::exports::ruma_identifiers }; |     let ruma_identifiers = quote! { #ruma_common::exports::ruma_identifiers }; | ||||||
|     let serde = quote! { #ruma_events::exports::serde }; |     let serde = quote! { #ruma_common::exports::serde }; | ||||||
|     let serde_json = quote! { #ruma_events::exports::serde_json }; |     let serde_json = quote! { #ruma_common::exports::serde_json }; | ||||||
| 
 | 
 | ||||||
|     let ident = &input.ident; |     let ident = &input.ident; | ||||||
|     let doc = format!("Redacted form of [`{}`]", ident); |     let doc = format!("Redacted form of [`{}`]", ident); | ||||||
| @ -241,9 +241,9 @@ fn generate_redacted_event_content( | |||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     let (has_deserialize_fields, has_serialize_fields) = if kept_redacted_fields.is_empty() { |     let (has_deserialize_fields, has_serialize_fields) = if kept_redacted_fields.is_empty() { | ||||||
|         (quote! { #ruma_events::HasDeserializeFields::False }, quote! { false }) |         (quote! { #ruma_common::events::HasDeserializeFields::False }, quote! { false }) | ||||||
|     } else { |     } else { | ||||||
|         (quote! { #ruma_events::HasDeserializeFields::True }, quote! { true }) |         (quote! { #ruma_common::events::HasDeserializeFields::True }, quote! { true }) | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     let constructor = kept_redacted_fields.is_empty().then(|| { |     let constructor = kept_redacted_fields.is_empty().then(|| { | ||||||
| @ -259,28 +259,28 @@ fn generate_redacted_event_content( | |||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     let redacted_event_content = |     let redacted_event_content = | ||||||
|         generate_event_content_impl(&redacted_ident, event_type, ruma_events); |         generate_event_content_impl(&redacted_ident, event_type, ruma_common); | ||||||
| 
 | 
 | ||||||
|     let marker_trait_impl = match event_kind { |     let marker_trait_impl = match event_kind { | ||||||
|         Some(EventKind::MessageLike) => quote! { |         Some(EventKind::MessageLike) => quote! { | ||||||
|             #[automatically_derived] |             #[automatically_derived] | ||||||
|             impl #ruma_events::RedactedMessageLikeEventContent for #redacted_ident {} |             impl #ruma_common::events::RedactedMessageLikeEventContent for #redacted_ident {} | ||||||
|         }, |         }, | ||||||
|         Some(EventKind::State) => quote! { |         Some(EventKind::State) => quote! { | ||||||
|             #[automatically_derived] |             #[automatically_derived] | ||||||
|             impl #ruma_events::RedactedStateEventContent for #redacted_ident {} |             impl #ruma_common::events::RedactedStateEventContent for #redacted_ident {} | ||||||
|         }, |         }, | ||||||
|         _ => TokenStream::new(), |         _ => TokenStream::new(), | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     let static_event_content_impl = event_kind.map(|k| { |     let static_event_content_impl = event_kind.map(|k| { | ||||||
|         generate_static_event_content_impl(&redacted_ident, k, true, event_type, ruma_events) |         generate_static_event_content_impl(&redacted_ident, k, true, event_type, ruma_common) | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     Ok(quote! { |     Ok(quote! { | ||||||
|         // this is the non redacted event content's impl
 |         // this is the non redacted event content's impl
 | ||||||
|         #[automatically_derived] |         #[automatically_derived] | ||||||
|         impl #ruma_events::RedactContent for #ident { |         impl #ruma_common::events::RedactContent for #ident { | ||||||
|             type Redacted = #redacted_ident; |             type Redacted = #redacted_ident; | ||||||
| 
 | 
 | ||||||
|             fn redact(self, version: &#ruma_identifiers::RoomVersionId) -> #redacted_ident { |             fn redact(self, version: &#ruma_identifiers::RoomVersionId) -> #redacted_ident { | ||||||
| @ -300,7 +300,7 @@ fn generate_redacted_event_content( | |||||||
|         #redacted_event_content |         #redacted_event_content | ||||||
| 
 | 
 | ||||||
|         #[automatically_derived] |         #[automatically_derived] | ||||||
|         impl #ruma_events::RedactedEventContent for #redacted_ident { |         impl #ruma_common::events::RedactedEventContent for #redacted_ident { | ||||||
|             fn empty(ev_type: &str) -> #serde_json::Result<Self> { |             fn empty(ev_type: &str) -> #serde_json::Result<Self> { | ||||||
|                 if ev_type != #event_type { |                 if ev_type != #event_type { | ||||||
|                     return Err(#serde::de::Error::custom( |                     return Err(#serde::de::Error::custom( | ||||||
| @ -315,7 +315,7 @@ fn generate_redacted_event_content( | |||||||
|                 #has_serialize_fields |                 #has_serialize_fields | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             fn has_deserialize_fields() -> #ruma_events::HasDeserializeFields { |             fn has_deserialize_fields() -> #ruma_common::events::HasDeserializeFields { | ||||||
|                 #has_deserialize_fields |                 #has_deserialize_fields | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @ -329,7 +329,7 @@ fn generate_event_type_aliases( | |||||||
|     event_kind: EventKind, |     event_kind: EventKind, | ||||||
|     ident: &Ident, |     ident: &Ident, | ||||||
|     event_type: &str, |     event_type: &str, | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
| ) -> syn::Result<TokenStream> { | ) -> syn::Result<TokenStream> { | ||||||
|     // The redaction module has its own event types.
 |     // The redaction module has its own event types.
 | ||||||
|     if ident == "RoomRedactionEventContent" { |     if ident == "RoomRedactionEventContent" { | ||||||
| @ -374,7 +374,7 @@ fn generate_event_type_aliases( | |||||||
| 
 | 
 | ||||||
|         quote! { |         quote! { | ||||||
|             #[doc = #ev_type_doc] |             #[doc = #ev_type_doc] | ||||||
|             pub type #ev_type = #ruma_events::#ev_struct<#content_struct>; |             pub type #ev_type = #ruma_common::events::#ev_struct<#content_struct>; | ||||||
|         } |         } | ||||||
|     }) |     }) | ||||||
|     .collect(); |     .collect(); | ||||||
| @ -385,7 +385,7 @@ fn generate_event_type_aliases( | |||||||
| fn generate_marker_trait_impl( | fn generate_marker_trait_impl( | ||||||
|     event_kind: EventKind, |     event_kind: EventKind, | ||||||
|     ident: &Ident, |     ident: &Ident, | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
| ) -> syn::Result<TokenStream> { | ) -> syn::Result<TokenStream> { | ||||||
|     let marker_trait = match event_kind { |     let marker_trait = match event_kind { | ||||||
|         EventKind::GlobalAccountData => quote! { GlobalAccountDataEventContent }, |         EventKind::GlobalAccountData => quote! { GlobalAccountDataEventContent }, | ||||||
| @ -408,21 +408,21 @@ fn generate_marker_trait_impl( | |||||||
| 
 | 
 | ||||||
|     Ok(quote! { |     Ok(quote! { | ||||||
|         #[automatically_derived] |         #[automatically_derived] | ||||||
|         impl #ruma_events::#marker_trait for #ident {} |         impl #ruma_common::events::#marker_trait for #ident {} | ||||||
|     }) |     }) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn generate_event_content_impl( | fn generate_event_content_impl( | ||||||
|     ident: &Ident, |     ident: &Ident, | ||||||
|     event_type: &LitStr, |     event_type: &LitStr, | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
| ) -> TokenStream { | ) -> TokenStream { | ||||||
|     let serde = quote! { #ruma_events::exports::serde }; |     let serde = quote! { #ruma_common::exports::serde }; | ||||||
|     let serde_json = quote! { #ruma_events::exports::serde_json }; |     let serde_json = quote! { #ruma_common::exports::serde_json }; | ||||||
| 
 | 
 | ||||||
|     quote! { |     quote! { | ||||||
|         #[automatically_derived] |         #[automatically_derived] | ||||||
|         impl #ruma_events::EventContent for #ident { |         impl #ruma_common::events::EventContent for #ident { | ||||||
|             fn event_type(&self) -> &str { |             fn event_type(&self) -> &str { | ||||||
|                 #event_type |                 #event_type | ||||||
|             } |             } | ||||||
| @ -448,7 +448,7 @@ fn generate_static_event_content_impl( | |||||||
|     event_kind: EventKind, |     event_kind: EventKind, | ||||||
|     redacted: bool, |     redacted: bool, | ||||||
|     event_type: &LitStr, |     event_type: &LitStr, | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
| ) -> TokenStream { | ) -> TokenStream { | ||||||
|     let event_kind = match event_kind { |     let event_kind = match event_kind { | ||||||
|         EventKind::GlobalAccountData => quote! { GlobalAccountData }, |         EventKind::GlobalAccountData => quote! { GlobalAccountData }, | ||||||
| @ -466,8 +466,9 @@ fn generate_static_event_content_impl( | |||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     quote! { |     quote! { | ||||||
|         impl #ruma_events::StaticEventContent for #ident { |         impl #ruma_common::events::StaticEventContent for #ident { | ||||||
|             const KIND: #ruma_events::EventKind = #ruma_events::EventKind::#event_kind; |             const KIND: #ruma_common::events::EventKind = | ||||||
|  |                 #ruma_common::events::EventKind::#event_kind; | ||||||
|             const TYPE: &'static ::std::primitive::str = #event_type; |             const TYPE: &'static ::std::primitive::str = #event_type; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -13,7 +13,7 @@ use super::{ | |||||||
| pub fn expand_event_enums(input: &EventEnumDecl) -> syn::Result<TokenStream> { | pub fn expand_event_enums(input: &EventEnumDecl) -> syn::Result<TokenStream> { | ||||||
|     use EventKindVariation as V; |     use EventKindVariation as V; | ||||||
| 
 | 
 | ||||||
|     let ruma_events = crate::import_ruma_events(); |     let ruma_common = crate::import_ruma_common(); | ||||||
| 
 | 
 | ||||||
|     let mut res = TokenStream::new(); |     let mut res = TokenStream::new(); | ||||||
| 
 | 
 | ||||||
| @ -25,31 +25,31 @@ pub fn expand_event_enums(input: &EventEnumDecl) -> syn::Result<TokenStream> { | |||||||
| 
 | 
 | ||||||
|     let events = &events; |     let events = &events; | ||||||
|     let variants = &variants; |     let variants = &variants; | ||||||
|     let ruma_events = &ruma_events; |     let ruma_common = &ruma_common; | ||||||
| 
 | 
 | ||||||
|     res.extend(expand_event_enum(kind, V::Full, events, attrs, variants, ruma_events)); |     res.extend(expand_event_enum(kind, V::Full, events, attrs, variants, ruma_common)); | ||||||
|     res.extend(expand_content_enum(kind, events, attrs, variants, ruma_events)); |     res.extend(expand_content_enum(kind, events, attrs, variants, ruma_common)); | ||||||
| 
 | 
 | ||||||
|     if matches!(kind, EventKind::Ephemeral | EventKind::MessageLike | EventKind::State) { |     if matches!(kind, EventKind::Ephemeral | EventKind::MessageLike | EventKind::State) { | ||||||
|         res.extend(expand_event_enum(kind, V::Sync, events, attrs, variants, ruma_events)); |         res.extend(expand_event_enum(kind, V::Sync, events, attrs, variants, ruma_common)); | ||||||
|         res.extend(expand_from_full_event(kind, V::Full, variants)); |         res.extend(expand_from_full_event(kind, V::Full, variants)); | ||||||
|         res.extend(expand_into_full_event(kind, V::Sync, variants, ruma_events)); |         res.extend(expand_into_full_event(kind, V::Sync, variants, ruma_common)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if matches!(kind, EventKind::State) { |     if matches!(kind, EventKind::State) { | ||||||
|         res.extend(expand_event_enum(kind, V::Stripped, events, attrs, variants, ruma_events)); |         res.extend(expand_event_enum(kind, V::Stripped, events, attrs, variants, ruma_common)); | ||||||
|         res.extend(expand_event_enum(kind, V::Initial, events, attrs, variants, ruma_events)); |         res.extend(expand_event_enum(kind, V::Initial, events, attrs, variants, ruma_common)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if matches!(kind, EventKind::MessageLike | EventKind::State) { |     if matches!(kind, EventKind::MessageLike | EventKind::State) { | ||||||
|         res.extend(expand_event_enum(kind, V::Redacted, events, attrs, variants, ruma_events)); |         res.extend(expand_event_enum(kind, V::Redacted, events, attrs, variants, ruma_common)); | ||||||
|         res.extend(expand_event_enum(kind, V::RedactedSync, events, attrs, variants, ruma_events)); |         res.extend(expand_event_enum(kind, V::RedactedSync, events, attrs, variants, ruma_common)); | ||||||
|         res.extend(expand_redact(kind, V::Full, variants, ruma_events)); |         res.extend(expand_redact(kind, V::Full, variants, ruma_common)); | ||||||
|         res.extend(expand_redact(kind, V::Sync, variants, ruma_events)); |         res.extend(expand_redact(kind, V::Sync, variants, ruma_common)); | ||||||
|         res.extend(expand_possibly_redacted_enum(kind, V::Full, ruma_events)); |         res.extend(expand_possibly_redacted_enum(kind, V::Full, ruma_common)); | ||||||
|         res.extend(expand_possibly_redacted_enum(kind, V::Sync, ruma_events)); |         res.extend(expand_possibly_redacted_enum(kind, V::Sync, ruma_common)); | ||||||
|         res.extend(expand_from_full_event(kind, V::Redacted, variants)); |         res.extend(expand_from_full_event(kind, V::Redacted, variants)); | ||||||
|         res.extend(expand_into_full_event(kind, V::RedactedSync, variants, ruma_events)); |         res.extend(expand_into_full_event(kind, V::RedactedSync, variants, ruma_common)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     Ok(res) |     Ok(res) | ||||||
| @ -61,17 +61,17 @@ fn expand_event_enum( | |||||||
|     events: &[LitStr], |     events: &[LitStr], | ||||||
|     attrs: &[Attribute], |     attrs: &[Attribute], | ||||||
|     variants: &[EventEnumVariant], |     variants: &[EventEnumVariant], | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
| ) -> TokenStream { | ) -> TokenStream { | ||||||
|     let event_struct = kind.to_event_ident(var); |     let event_struct = kind.to_event_ident(var); | ||||||
|     let ident = kind.to_event_enum_ident(var); |     let ident = kind.to_event_enum_ident(var); | ||||||
| 
 | 
 | ||||||
|     let variant_decls = variants.iter().map(|v| v.decl()); |     let variant_decls = variants.iter().map(|v| v.decl()); | ||||||
|     let content: Vec<_> = |     let content: Vec<_> = | ||||||
|         events.iter().map(|event| to_event_path(event, kind, var, ruma_events)).collect(); |         events.iter().map(|event| to_event_path(event, kind, var, ruma_common)).collect(); | ||||||
| 
 | 
 | ||||||
|     let deserialize_impl = expand_deserialize_impl(kind, var, events, variants, ruma_events); |     let deserialize_impl = expand_deserialize_impl(kind, var, events, variants, ruma_common); | ||||||
|     let field_accessor_impl = expand_accessor_methods(kind, var, variants, ruma_events); |     let field_accessor_impl = expand_accessor_methods(kind, var, variants, ruma_common); | ||||||
|     let from_impl = expand_from_impl(&ident, &content, variants); |     let from_impl = expand_from_impl(&ident, &content, variants); | ||||||
| 
 | 
 | ||||||
|     quote! { |     quote! { | ||||||
| @ -86,7 +86,11 @@ fn expand_event_enum( | |||||||
|             )* |             )* | ||||||
|             /// An event not defined by the Matrix specification
 |             /// An event not defined by the Matrix specification
 | ||||||
|             #[doc(hidden)] |             #[doc(hidden)] | ||||||
|             _Custom(#ruma_events::#event_struct<#ruma_events::_custom::CustomEventContent>), |             _Custom( | ||||||
|  |                 #ruma_common::events::#event_struct< | ||||||
|  |                     #ruma_common::events::_custom::CustomEventContent, | ||||||
|  |                 >, | ||||||
|  |             ), | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         #deserialize_impl |         #deserialize_impl | ||||||
| @ -100,11 +104,11 @@ fn expand_deserialize_impl( | |||||||
|     var: EventKindVariation, |     var: EventKindVariation, | ||||||
|     events: &[LitStr], |     events: &[LitStr], | ||||||
|     variants: &[EventEnumVariant], |     variants: &[EventEnumVariant], | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
| ) -> TokenStream { | ) -> TokenStream { | ||||||
|     let ruma_serde = quote! { #ruma_events::exports::ruma_serde }; |     let ruma_serde = quote! { #ruma_common::exports::ruma_serde }; | ||||||
|     let serde = quote! { #ruma_events::exports::serde }; |     let serde = quote! { #ruma_common::exports::serde }; | ||||||
|     let serde_json = quote! { #ruma_events::exports::serde_json }; |     let serde_json = quote! { #ruma_common::exports::serde_json }; | ||||||
| 
 | 
 | ||||||
|     let ident = kind.to_event_enum_ident(var); |     let ident = kind.to_event_enum_ident(var); | ||||||
| 
 | 
 | ||||||
| @ -113,7 +117,7 @@ fn expand_deserialize_impl( | |||||||
|         quote! { #(#attrs)* } |         quote! { #(#attrs)* } | ||||||
|     }); |     }); | ||||||
|     let self_variants = variants.iter().map(|v| v.ctor(quote! { Self })); |     let self_variants = variants.iter().map(|v| v.ctor(quote! { Self })); | ||||||
|     let content = events.iter().map(|event| to_event_path(event, kind, var, ruma_events)); |     let content = events.iter().map(|event| to_event_path(event, kind, var, ruma_common)); | ||||||
| 
 | 
 | ||||||
|     quote! { |     quote! { | ||||||
|         impl<'de> #serde::de::Deserialize<'de> for #ident { |         impl<'de> #serde::de::Deserialize<'de> for #ident { | ||||||
| @ -124,7 +128,7 @@ fn expand_deserialize_impl( | |||||||
|                 use #serde::de::Error as _; |                 use #serde::de::Error as _; | ||||||
| 
 | 
 | ||||||
|                 let json = Box::<#serde_json::value::RawValue>::deserialize(deserializer)?; |                 let json = Box::<#serde_json::value::RawValue>::deserialize(deserializer)?; | ||||||
|                 let #ruma_events::EventTypeDeHelper { ev_type, .. } = |                 let #ruma_common::events::EventTypeDeHelper { ev_type, .. } = | ||||||
|                     #ruma_serde::from_raw_json_value(&json)?; |                     #ruma_serde::from_raw_json_value(&json)?; | ||||||
| 
 | 
 | ||||||
|                 match &*ev_type { |                 match &*ev_type { | ||||||
| @ -202,9 +206,9 @@ fn expand_into_full_event( | |||||||
|     kind: EventKind, |     kind: EventKind, | ||||||
|     var: EventKindVariation, |     var: EventKindVariation, | ||||||
|     variants: &[EventEnumVariant], |     variants: &[EventEnumVariant], | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
| ) -> TokenStream { | ) -> TokenStream { | ||||||
|     let ruma_identifiers = quote! { #ruma_events::exports::ruma_identifiers }; |     let ruma_identifiers = quote! { #ruma_common::exports::ruma_identifiers }; | ||||||
| 
 | 
 | ||||||
|     let ident = kind.to_event_enum_ident(var); |     let ident = kind.to_event_enum_ident(var); | ||||||
|     let full = kind.to_event_enum_ident(var.to_full()); |     let full = kind.to_event_enum_ident(var.to_full()); | ||||||
| @ -241,17 +245,17 @@ fn expand_content_enum( | |||||||
|     events: &[LitStr], |     events: &[LitStr], | ||||||
|     attrs: &[Attribute], |     attrs: &[Attribute], | ||||||
|     variants: &[EventEnumVariant], |     variants: &[EventEnumVariant], | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
| ) -> TokenStream { | ) -> TokenStream { | ||||||
|     let serde = quote! { #ruma_events::exports::serde }; |     let serde = quote! { #ruma_common::exports::serde }; | ||||||
|     let serde_json = quote! { #ruma_events::exports::serde_json }; |     let serde_json = quote! { #ruma_common::exports::serde_json }; | ||||||
| 
 | 
 | ||||||
|     let ident = kind.to_content_enum(); |     let ident = kind.to_content_enum(); | ||||||
| 
 | 
 | ||||||
|     let event_type_str = events; |     let event_type_str = events; | ||||||
| 
 | 
 | ||||||
|     let content: Vec<_> = |     let content: Vec<_> = | ||||||
|         events.iter().map(|ev| to_event_content_path(kind, ev, None, ruma_events)).collect(); |         events.iter().map(|ev| to_event_content_path(kind, ev, None, ruma_common)).collect(); | ||||||
| 
 | 
 | ||||||
|     let variant_decls = variants.iter().map(|v| v.decl()).collect::<Vec<_>>(); |     let variant_decls = variants.iter().map(|v| v.decl()).collect::<Vec<_>>(); | ||||||
| 
 | 
 | ||||||
| @ -262,11 +266,11 @@ fn expand_content_enum( | |||||||
|     let variant_arms = variants.iter().map(|v| v.match_arm(quote! { Self })).collect::<Vec<_>>(); |     let variant_arms = variants.iter().map(|v| v.match_arm(quote! { Self })).collect::<Vec<_>>(); | ||||||
|     let variant_ctors = variants.iter().map(|v| v.ctor(quote! { Self })); |     let variant_ctors = variants.iter().map(|v| v.ctor(quote! { Self })); | ||||||
| 
 | 
 | ||||||
|     let marker_trait_impl = expand_marker_trait_impl(kind, ruma_events); |     let marker_trait_impl = expand_marker_trait_impl(kind, ruma_common); | ||||||
|     let from_impl = expand_from_impl(&ident, &content, variants); |     let from_impl = expand_from_impl(&ident, &content, variants); | ||||||
| 
 | 
 | ||||||
|     let serialize_custom_event_error_path = |     let serialize_custom_event_error_path = | ||||||
|         quote! { #ruma_events::serialize_custom_event_error }.to_string(); |         quote! { #ruma_common::events::serialize_custom_event_error }.to_string(); | ||||||
| 
 | 
 | ||||||
|     quote! { |     quote! { | ||||||
|         #( #attrs )* |         #( #attrs )* | ||||||
| @ -287,7 +291,7 @@ fn expand_content_enum( | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         #[automatically_derived] |         #[automatically_derived] | ||||||
|         impl #ruma_events::EventContent for #ident { |         impl #ruma_common::events::EventContent for #ident { | ||||||
|             fn event_type(&self) -> &::std::primitive::str { |             fn event_type(&self) -> &::std::primitive::str { | ||||||
|                 match self { |                 match self { | ||||||
|                     #( #variant_arms(content) => content.event_type(), )* |                     #( #variant_arms(content) => content.event_type(), )* | ||||||
| @ -324,9 +328,9 @@ fn expand_redact( | |||||||
|     kind: EventKind, |     kind: EventKind, | ||||||
|     var: EventKindVariation, |     var: EventKindVariation, | ||||||
|     variants: &[EventEnumVariant], |     variants: &[EventEnumVariant], | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
| ) -> TokenStream { | ) -> TokenStream { | ||||||
|     let ruma_identifiers = quote! { #ruma_events::exports::ruma_identifiers }; |     let ruma_identifiers = quote! { #ruma_common::exports::ruma_identifiers }; | ||||||
| 
 | 
 | ||||||
|     let ident = kind.to_event_enum_ident(var); |     let ident = kind.to_event_enum_ident(var); | ||||||
|     let redacted_enum = kind.to_event_enum_ident(var.to_redacted()); |     let redacted_enum = kind.to_event_enum_ident(var.to_redacted()); | ||||||
| @ -336,22 +340,22 @@ fn expand_redact( | |||||||
| 
 | 
 | ||||||
|     quote! { |     quote! { | ||||||
|         #[automatically_derived] |         #[automatically_derived] | ||||||
|         impl #ruma_events::Redact for #ident { |         impl #ruma_common::events::Redact for #ident { | ||||||
|             type Redacted = #redacted_enum; |             type Redacted = #redacted_enum; | ||||||
| 
 | 
 | ||||||
|             fn redact( |             fn redact( | ||||||
|                 self, |                 self, | ||||||
|                 redaction: #ruma_events::room::redaction::SyncRoomRedactionEvent, |                 redaction: #ruma_common::events::room::redaction::SyncRoomRedactionEvent, | ||||||
|                 version: &#ruma_identifiers::RoomVersionId, |                 version: &#ruma_identifiers::RoomVersionId, | ||||||
|             ) -> #redacted_enum { |             ) -> #redacted_enum { | ||||||
|                 match self { |                 match self { | ||||||
|                     #( |                     #( | ||||||
|                         #self_variants(event) => #redacted_variants( |                         #self_variants(event) => #redacted_variants( | ||||||
|                             #ruma_events::Redact::redact(event, redaction, version), |                             #ruma_common::events::Redact::redact(event, redaction, version), | ||||||
|                         ), |                         ), | ||||||
|                     )* |                     )* | ||||||
|                     Self::_Custom(event) => #redacted_enum::_Custom( |                     Self::_Custom(event) => #redacted_enum::_Custom( | ||||||
|                         #ruma_events::Redact::redact(event, redaction, version), |                         #ruma_common::events::Redact::redact(event, redaction, version), | ||||||
|                     ) |                     ) | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| @ -362,11 +366,11 @@ fn expand_redact( | |||||||
| fn expand_possibly_redacted_enum( | fn expand_possibly_redacted_enum( | ||||||
|     kind: EventKind, |     kind: EventKind, | ||||||
|     var: EventKindVariation, |     var: EventKindVariation, | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
| ) -> TokenStream { | ) -> TokenStream { | ||||||
|     let ruma_serde = quote! { #ruma_events::exports::ruma_serde }; |     let ruma_serde = quote! { #ruma_common::exports::ruma_serde }; | ||||||
|     let serde = quote! { #ruma_events::exports::serde }; |     let serde = quote! { #ruma_common::exports::serde }; | ||||||
|     let serde_json = quote! { #ruma_events::exports::serde_json }; |     let serde_json = quote! { #ruma_common::exports::serde_json }; | ||||||
| 
 | 
 | ||||||
|     let ident = format_ident!("AnyPossiblyRedacted{}", kind.to_event_ident(var)); |     let ident = format_ident!("AnyPossiblyRedacted{}", kind.to_event_ident(var)); | ||||||
|     let regular_enum_ident = kind.to_event_enum_ident(var); |     let regular_enum_ident = kind.to_event_enum_ident(var); | ||||||
| @ -390,7 +394,7 @@ fn expand_possibly_redacted_enum( | |||||||
|                 D: #serde::de::Deserializer<'de>, |                 D: #serde::de::Deserializer<'de>, | ||||||
|             { |             { | ||||||
|                 let json = Box::<#serde_json::value::RawValue>::deserialize(deserializer)?; |                 let json = Box::<#serde_json::value::RawValue>::deserialize(deserializer)?; | ||||||
|                 let #ruma_events::RedactionDeHelper { unsigned } = |                 let #ruma_common::events::RedactionDeHelper { unsigned } = | ||||||
|                     #ruma_serde::from_raw_json_value(&json)?; |                     #ruma_serde::from_raw_json_value(&json)?; | ||||||
| 
 | 
 | ||||||
|                 Ok(match unsigned { |                 Ok(match unsigned { | ||||||
| @ -404,7 +408,7 @@ fn expand_possibly_redacted_enum( | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn expand_marker_trait_impl(kind: EventKind, ruma_events: &TokenStream) -> TokenStream { | fn expand_marker_trait_impl(kind: EventKind, ruma_common: &TokenStream) -> TokenStream { | ||||||
|     let marker_trait = match kind { |     let marker_trait = match kind { | ||||||
|         EventKind::State => quote! { StateEventContent }, |         EventKind::State => quote! { StateEventContent }, | ||||||
|         EventKind::MessageLike => quote! { MessageLikeEventContent }, |         EventKind::MessageLike => quote! { MessageLikeEventContent }, | ||||||
| @ -418,7 +422,7 @@ fn expand_marker_trait_impl(kind: EventKind, ruma_events: &TokenStream) -> Token | |||||||
|     let ident = kind.to_content_enum(); |     let ident = kind.to_content_enum(); | ||||||
|     quote! { |     quote! { | ||||||
|         #[automatically_derived] |         #[automatically_derived] | ||||||
|         impl #ruma_events::#marker_trait for #ident {} |         impl #ruma_common::events::#marker_trait for #ident {} | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -426,7 +430,7 @@ fn expand_accessor_methods( | |||||||
|     kind: EventKind, |     kind: EventKind, | ||||||
|     var: EventKindVariation, |     var: EventKindVariation, | ||||||
|     variants: &[EventEnumVariant], |     variants: &[EventEnumVariant], | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
| ) -> TokenStream { | ) -> TokenStream { | ||||||
|     let ident = kind.to_event_enum_ident(var); |     let ident = kind.to_event_enum_ident(var); | ||||||
|     let self_variants: Vec<_> = variants.iter().map(|v| v.match_arm(quote! { Self })).collect(); |     let self_variants: Vec<_> = variants.iter().map(|v| v.match_arm(quote! { Self })).collect(); | ||||||
| @ -448,7 +452,7 @@ fn expand_accessor_methods( | |||||||
|                         Self::_Custom(event) => { |                         Self::_Custom(event) => { | ||||||
|                             event.prev_content.as_ref().map(|c| #content_enum::_Custom { |                             event.prev_content.as_ref().map(|c| #content_enum::_Custom { | ||||||
|                                 event_type: crate::PrivOwnedStr( |                                 event_type: crate::PrivOwnedStr( | ||||||
|                                     #ruma_events::EventContent::event_type(c).into(), |                                     #ruma_common::events::EventContent::event_type(c).into(), | ||||||
|                                 ), |                                 ), | ||||||
|                             }) |                             }) | ||||||
|                         }, |                         }, | ||||||
| @ -464,7 +468,7 @@ fn expand_accessor_methods( | |||||||
|                     #( #self_variants(event) => #content_variants(event.content.clone()), )* |                     #( #self_variants(event) => #content_variants(event.content.clone()), )* | ||||||
|                     Self::_Custom(event) => #content_enum::_Custom { |                     Self::_Custom(event) => #content_enum::_Custom { | ||||||
|                         event_type: crate::PrivOwnedStr( |                         event_type: crate::PrivOwnedStr( | ||||||
|                             #ruma_events::EventContent::event_type(&event.content).into(), |                             #ruma_common::events::EventContent::event_type(&event.content).into(), | ||||||
|                         ), |                         ), | ||||||
|                     }, |                     }, | ||||||
|                 } |                 } | ||||||
| @ -478,7 +482,7 @@ fn expand_accessor_methods( | |||||||
|         has_field(kind, var).then(|| { |         has_field(kind, var).then(|| { | ||||||
|             let docs = format!("Returns this event's {} field.", name); |             let docs = format!("Returns this event's {} field.", name); | ||||||
|             let ident = Ident::new(name, Span::call_site()); |             let ident = Ident::new(name, Span::call_site()); | ||||||
|             let field_type = field_return_type(name, var, ruma_events); |             let field_type = field_return_type(name, var, ruma_common); | ||||||
|             let variants = variants.iter().map(|v| v.match_arm(quote! { Self })); |             let variants = variants.iter().map(|v| v.match_arm(quote! { Self })); | ||||||
| 
 | 
 | ||||||
|             quote! { |             quote! { | ||||||
| @ -500,9 +504,9 @@ fn expand_accessor_methods( | |||||||
|             pub fn event_type(&self) -> &::std::primitive::str { |             pub fn event_type(&self) -> &::std::primitive::str { | ||||||
|                 match self { |                 match self { | ||||||
|                     #( #self_variants(event) => |                     #( #self_variants(event) => | ||||||
|                         #ruma_events::EventContent::event_type(&event.content), )* |                         #ruma_common::events::EventContent::event_type(&event.content), )* | ||||||
|                     Self::_Custom(event) => |                     Self::_Custom(event) => | ||||||
|                         #ruma_events::EventContent::event_type(&event.content), |                         #ruma_common::events::EventContent::event_type(&event.content), | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
| @ -517,7 +521,7 @@ fn to_event_path( | |||||||
|     name: &LitStr, |     name: &LitStr, | ||||||
|     kind: EventKind, |     kind: EventKind, | ||||||
|     var: EventKindVariation, |     var: EventKindVariation, | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
| ) -> TokenStream { | ) -> TokenStream { | ||||||
|     let span = name.span(); |     let span = name.span(); | ||||||
|     let name = name.value(); |     let name = name.value(); | ||||||
| @ -540,14 +544,14 @@ fn to_event_path( | |||||||
|     } else { |     } else { | ||||||
|         format_ident!("{}{}Event", var, event) |         format_ident!("{}{}Event", var, event) | ||||||
|     }; |     }; | ||||||
|     quote! { #ruma_events::#( #path )::*::#event_name } |     quote! { #ruma_common::events::#( #path )::*::#event_name } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn to_event_content_path( | fn to_event_content_path( | ||||||
|     kind: EventKind, |     kind: EventKind, | ||||||
|     name: &LitStr, |     name: &LitStr, | ||||||
|     prefix: Option<&str>, |     prefix: Option<&str>, | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
| ) -> TokenStream { | ) -> TokenStream { | ||||||
|     let span = name.span(); |     let span = name.span(); | ||||||
|     let name = name.value(); |     let name = name.value(); | ||||||
| @ -572,7 +576,7 @@ fn to_event_content_path( | |||||||
|     let path = path.iter().map(|s| Ident::new(s, span)); |     let path = path.iter().map(|s| Ident::new(s, span)); | ||||||
| 
 | 
 | ||||||
|     quote! { |     quote! { | ||||||
|         #ruma_events::#( #path )::*::#content_str |         #ruma_common::events::#( #path )::*::#content_str | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -600,10 +604,9 @@ fn to_camel_case(name: &LitStr) -> syn::Result<Ident> { | |||||||
| fn field_return_type( | fn field_return_type( | ||||||
|     name: &str, |     name: &str, | ||||||
|     var: EventKindVariation, |     var: EventKindVariation, | ||||||
|     ruma_events: &TokenStream, |     ruma_common: &TokenStream, | ||||||
| ) -> TokenStream { | ) -> TokenStream { | ||||||
|     let ruma_common = quote! { #ruma_events::exports::ruma_common }; |     let ruma_identifiers = quote! { #ruma_common::exports::ruma_identifiers }; | ||||||
|     let ruma_identifiers = quote! { #ruma_events::exports::ruma_identifiers }; |  | ||||||
| 
 | 
 | ||||||
|     match name { |     match name { | ||||||
|         "origin_server_ts" => quote! { #ruma_common::MilliSecondsSinceUnixEpoch }, |         "origin_server_ts" => quote! { #ruma_common::MilliSecondsSinceUnixEpoch }, | ||||||
| @ -613,9 +616,9 @@ fn field_return_type( | |||||||
|         "state_key" => quote! { ::std::primitive::str }, |         "state_key" => quote! { ::std::primitive::str }, | ||||||
|         "unsigned" => { |         "unsigned" => { | ||||||
|             if var.is_redacted() { |             if var.is_redacted() { | ||||||
|                 quote! { #ruma_events::RedactedUnsigned } |                 quote! { #ruma_common::events::RedactedUnsigned } | ||||||
|             } else { |             } else { | ||||||
|                 quote! { #ruma_events::Unsigned } |                 quote! { #ruma_common::events::Unsigned } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         _ => panic!("the `ruma_macros::event_enum::EVENT_FIELD` const was changed"), |         _ => panic!("the `ruma_macros::event_enum::EVENT_FIELD` const was changed"), | ||||||
|  | |||||||
| @ -6,9 +6,9 @@ use super::event_parse::{EventEnumEntry, EventEnumInput, EventKind}; | |||||||
| 
 | 
 | ||||||
| pub fn expand_event_type_enum( | pub fn expand_event_type_enum( | ||||||
|     input: EventEnumInput, |     input: EventEnumInput, | ||||||
|     ruma_events: TokenStream, |     ruma_common: TokenStream, | ||||||
| ) -> syn::Result<TokenStream> { | ) -> syn::Result<TokenStream> { | ||||||
|     let ruma_serde = quote! { #ruma_events::exports::ruma_serde }; |     let ruma_serde = quote! { #ruma_common::exports::ruma_serde }; | ||||||
| 
 | 
 | ||||||
|     let mut room: Vec<&Vec<EventEnumEntry>> = vec![]; |     let mut room: Vec<&Vec<EventEnumEntry>> = vec![]; | ||||||
|     let mut state: Vec<&Vec<EventEnumEntry>> = vec![]; |     let mut state: Vec<&Vec<EventEnumEntry>> = vec![]; | ||||||
|  | |||||||
| @ -71,7 +71,7 @@ mod serde; | |||||||
| //// supported:  https://github.com/rust-lang/rust/issues/74563
 | //// supported:  https://github.com/rust-lang/rust/issues/74563
 | ||||||
| #[proc_macro] | #[proc_macro] | ||||||
| pub fn event_enum(input: TokenStream) -> TokenStream { | pub fn event_enum(input: TokenStream) -> TokenStream { | ||||||
|     let ruma_events = import_ruma_events(); |     let ruma_common = import_ruma_common(); | ||||||
| 
 | 
 | ||||||
|     let event_enum_input = syn::parse_macro_input!(input as EventEnumInput); |     let event_enum_input = syn::parse_macro_input!(input as EventEnumInput); | ||||||
|     let enums = event_enum_input |     let enums = event_enum_input | ||||||
| @ -79,7 +79,7 @@ pub fn event_enum(input: TokenStream) -> TokenStream { | |||||||
|         .iter() |         .iter() | ||||||
|         .map(expand_event_enums) |         .map(expand_event_enums) | ||||||
|         .collect::<syn::Result<pm2::TokenStream>>(); |         .collect::<syn::Result<pm2::TokenStream>>(); | ||||||
|     let event_types = expand_event_type_enum(event_enum_input, ruma_events); |     let event_types = expand_event_type_enum(event_enum_input, ruma_common); | ||||||
|     event_types |     event_types | ||||||
|         .and_then(|types| { |         .and_then(|types| { | ||||||
|             enums.map(|mut enums| { |             enums.map(|mut enums| { | ||||||
| @ -94,10 +94,10 @@ pub fn event_enum(input: TokenStream) -> TokenStream { | |||||||
| /// Generates an implementation of `ruma_common::events::EventContent`.
 | /// Generates an implementation of `ruma_common::events::EventContent`.
 | ||||||
| #[proc_macro_derive(EventContent, attributes(ruma_event))] | #[proc_macro_derive(EventContent, attributes(ruma_event))] | ||||||
| pub fn derive_event_content(input: TokenStream) -> TokenStream { | pub fn derive_event_content(input: TokenStream) -> TokenStream { | ||||||
|     let ruma_events = import_ruma_events(); |     let ruma_common = import_ruma_common(); | ||||||
|     let input = parse_macro_input!(input as DeriveInput); |     let input = parse_macro_input!(input as DeriveInput); | ||||||
| 
 | 
 | ||||||
|     expand_event_content(&input, &ruma_events).unwrap_or_else(syn::Error::into_compile_error).into() |     expand_event_content(&input, &ruma_common).unwrap_or_else(syn::Error::into_compile_error).into() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// Generates implementations needed to serialize and deserialize Matrix events.
 | /// Generates implementations needed to serialize and deserialize Matrix events.
 | ||||||
| @ -107,21 +107,21 @@ pub fn derive_event(input: TokenStream) -> TokenStream { | |||||||
|     expand_event(input).unwrap_or_else(syn::Error::into_compile_error).into() |     expand_event(input).unwrap_or_else(syn::Error::into_compile_error).into() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub(crate) fn import_ruma_events() -> pm2::TokenStream { | pub(crate) fn import_ruma_common() -> pm2::TokenStream { | ||||||
|     if let Ok(FoundCrate::Name(name)) = crate_name("ruma-common") { |     if let Ok(FoundCrate::Name(name)) = crate_name("ruma-common") { | ||||||
|         let import = format_ident!("{}", name); |         let import = format_ident!("{}", name); | ||||||
|         quote! { ::#import::events } |         quote! { ::#import } | ||||||
|     } else if let Ok(FoundCrate::Name(name)) = crate_name("ruma") { |     } else if let Ok(FoundCrate::Name(name)) = crate_name("ruma") { | ||||||
|         let import = format_ident!("{}", name); |         let import = format_ident!("{}", name); | ||||||
|         quote! { ::#import::events } |         quote! { ::#import } | ||||||
|     } else if let Ok(FoundCrate::Name(name)) = crate_name("matrix-sdk") { |     } else if let Ok(FoundCrate::Name(name)) = crate_name("matrix-sdk") { | ||||||
|         let import = format_ident!("{}", name); |         let import = format_ident!("{}", name); | ||||||
|         quote! { ::#import::ruma::events } |         quote! { ::#import::ruma } | ||||||
|     } else if let Ok(FoundCrate::Name(name)) = crate_name("matrix-sdk-appservice") { |     } else if let Ok(FoundCrate::Name(name)) = crate_name("matrix-sdk-appservice") { | ||||||
|         let import = format_ident!("{}", name); |         let import = format_ident!("{}", name); | ||||||
|         quote! { ::#import::ruma::events } |         quote! { ::#import::ruma } | ||||||
|     } else { |     } else { | ||||||
|         quote! { ::ruma_common::events } |         quote! { ::ruma_common } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user