diff --git a/crates/ruma-events-macros/src/event_content.rs b/crates/ruma-events-macros/src/event_content.rs index 7b84c1c7..b3dc1a86 100644 --- a/crates/ruma-events-macros/src/event_content.rs +++ b/crates/ruma-events-macros/src/event_content.rs @@ -234,22 +234,6 @@ pub fn expand_event_content( }) } -/// Create a `BasicEventContent` implementation for a struct -pub fn expand_basic_event_content( - input: &DeriveInput, - ruma_events: &TokenStream, -) -> syn::Result { - let ident = input.ident.clone(); - let event_content_impl = expand_event_content(input, false, ruma_events)?; - - Ok(quote! { - #event_content_impl - - #[automatically_derived] - impl #ruma_events::BasicEventContent for #ident {} - }) -} - /// Create a `EphemeralRoomEventContent` implementation for a struct pub fn expand_ephemeral_room_event_content( input: &DeriveInput, diff --git a/crates/ruma-events-macros/src/event_enum.rs b/crates/ruma-events-macros/src/event_enum.rs index 0186913a..f5d2e27f 100644 --- a/crates/ruma-events-macros/src/event_enum.rs +++ b/crates/ruma-events-macros/src/event_enum.rs @@ -680,14 +680,6 @@ fn marker_traits(kind: &EventKind, ruma_events: &TokenStream) -> TokenStream { #[automatically_derived] impl #ruma_events::EphemeralRoomEventContent for #ident {} }, - EventKind::GlobalAccountData => quote! { - #[automatically_derived] - impl #ruma_events::BasicEventContent for #ident {} - }, - EventKind::RoomAccountData => quote! { - #[automatically_derived] - impl #ruma_events::BasicEventContent for #ident {} - }, _ => TokenStream::new(), } } diff --git a/crates/ruma-events-macros/src/lib.rs b/crates/ruma-events-macros/src/lib.rs index 2823682c..88757954 100644 --- a/crates/ruma-events-macros/src/lib.rs +++ b/crates/ruma-events-macros/src/lib.rs @@ -17,8 +17,8 @@ use syn::{parse_macro_input, DeriveInput, Ident}; use self::{ event::expand_event, event_content::{ - expand_basic_event_content, expand_ephemeral_room_event_content, expand_event_content, - expand_message_event_content, expand_room_event_content, expand_state_event_content, + expand_ephemeral_room_event_content, expand_event_content, expand_message_event_content, + expand_room_event_content, expand_state_event_content, }, event_enum::expand_event_enum, event_parse::EventEnumInput, @@ -63,17 +63,6 @@ pub fn derive_event_content(input: TokenStream) -> TokenStream { .into() } -/// Generates an implementation of `ruma_events::BasicEventContent` and it's super traits. -#[proc_macro_derive(BasicEventContent, attributes(ruma_event))] -pub fn derive_basic_event_content(input: TokenStream) -> TokenStream { - let ruma_events = import_ruma_events(); - let input = parse_macro_input!(input as DeriveInput); - - expand_basic_event_content(&input, &ruma_events) - .unwrap_or_else(syn::Error::into_compile_error) - .into() -} - /// Generates an implementation of `ruma_events::RoomEventContent` and it's super traits. #[proc_macro_derive(RoomEventContent, attributes(ruma_event))] pub fn derive_room_event_content(input: TokenStream) -> TokenStream { diff --git a/crates/ruma-events/CHANGELOG.md b/crates/ruma-events/CHANGELOG.md index 0fc168d6..32d19f2c 100644 --- a/crates/ruma-events/CHANGELOG.md +++ b/crates/ruma-events/CHANGELOG.md @@ -44,6 +44,7 @@ Breaking changes: * Move `FullyRead` from `EphemeralRoom` enum to `RoomAccountData` enum * Split `Basic` enum into `GlobalAccountData` and `RoomAccountData` enums * Remove `DummyEvent`, `DummyEventContent`, `RoomKeyEvent`, `RoomKeyEventContent` +* Remove `BasicEventContent` trait and derive Improvements: diff --git a/crates/ruma-events/src/direct.rs b/crates/ruma-events/src/direct.rs index 843d3b28..904a0ad0 100644 --- a/crates/ruma-events/src/direct.rs +++ b/crates/ruma-events/src/direct.rs @@ -5,7 +5,7 @@ use std::{ ops::{Deref, DerefMut}, }; -use ruma_events_macros::BasicEventContent; +use ruma_events_macros::EventContent; use ruma_identifiers::{RoomId, UserId}; use serde::{Deserialize, Serialize}; @@ -16,7 +16,7 @@ pub type DirectEvent = crate::GlobalAccountDataEvent; /// /// A mapping of `UserId`s to a list of `RoomId`s which are considered *direct* for that /// particular user. -#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] +#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[ruma_event(type = "m.direct")] pub struct DirectEventContent(pub BTreeMap>); diff --git a/crates/ruma-events/src/dummy.rs b/crates/ruma-events/src/dummy.rs index 66c6eefa..bbe22429 100644 --- a/crates/ruma-events/src/dummy.rs +++ b/crates/ruma-events/src/dummy.rs @@ -1,9 +1,9 @@ //! Types for the *m.dummy* event. -use ruma_events_macros::BasicEventContent; +use ruma_events_macros::EventContent; use serde::{Deserialize, Serialize}; /// The payload for `DummyEvent`. -#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] +#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[ruma_event(type = "m.dummy")] pub struct DummyToDeviceEventContent {} diff --git a/crates/ruma-events/src/event_kinds.rs b/crates/ruma-events/src/event_kinds.rs index 99756a3b..8801c4f5 100644 --- a/crates/ruma-events/src/event_kinds.rs +++ b/crates/ruma-events/src/event_kinds.rs @@ -4,21 +4,20 @@ use ruma_events_macros::Event; use ruma_identifiers::{EventId, RoomId, UserId}; use crate::{ - BasicEventContent, EphemeralRoomEventContent, EventContent, MessageEventContent, - RedactedMessageEventContent, RedactedStateEventContent, RedactedSyncUnsigned, RedactedUnsigned, - StateEventContent, Unsigned, + EphemeralRoomEventContent, EventContent, MessageEventContent, RedactedMessageEventContent, + RedactedStateEventContent, RedactedSyncUnsigned, RedactedUnsigned, StateEventContent, Unsigned, }; /// A global account data event. #[derive(Clone, Debug, Event)] -pub struct GlobalAccountDataEvent { +pub struct GlobalAccountDataEvent { /// Data specific to the event type. pub content: C, } /// A room account data event. #[derive(Clone, Debug, Event)] -pub struct RoomAccountDataEvent { +pub struct RoomAccountDataEvent { /// Data specific to the event type. pub content: C, } diff --git a/crates/ruma-events/src/forwarded_room_key.rs b/crates/ruma-events/src/forwarded_room_key.rs index 3e03258b..e7384020 100644 --- a/crates/ruma-events/src/forwarded_room_key.rs +++ b/crates/ruma-events/src/forwarded_room_key.rs @@ -1,6 +1,6 @@ //! Types for the *m.forwarded_room_key* event. -use ruma_events_macros::BasicEventContent; +use ruma_events_macros::EventContent; use ruma_identifiers::{EventEncryptionAlgorithm, RoomId}; use serde::{Deserialize, Serialize}; @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; /// /// To create an instance of this type, first create a `ForwardedRoomKeyToDeviceEventContentInit` /// and convert it via `ForwardedRoomKeyToDeviceEventContent::from` / `.into()`. -#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] +#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.forwarded_room_key")] pub struct ForwardedRoomKeyToDeviceEventContent { diff --git a/crates/ruma-events/src/fully_read.rs b/crates/ruma-events/src/fully_read.rs index a27aff44..76f2c8de 100644 --- a/crates/ruma-events/src/fully_read.rs +++ b/crates/ruma-events/src/fully_read.rs @@ -1,6 +1,6 @@ //! Types for the *m.fully_read* event. -use ruma_events_macros::BasicEventContent; +use ruma_events_macros::EventContent; use ruma_identifiers::EventId; use serde::{Deserialize, Serialize}; @@ -13,7 +13,7 @@ use crate::RoomAccountDataEvent; pub type FullyReadEvent = RoomAccountDataEvent; /// The payload for `FullyReadEvent`. -#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] +#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[ruma_event(type = "m.fully_read")] pub struct FullyReadEventContent { /// The event the user's read marker is located at in the room. diff --git a/crates/ruma-events/src/ignored_user_list.rs b/crates/ruma-events/src/ignored_user_list.rs index 3b309860..12697dc9 100644 --- a/crates/ruma-events/src/ignored_user_list.rs +++ b/crates/ruma-events/src/ignored_user_list.rs @@ -1,6 +1,6 @@ //! Types for the *m.ignored_user_list* event. -use ruma_events_macros::BasicEventContent; +use ruma_events_macros::EventContent; use ruma_identifiers::UserId; use serde::{Deserialize, Serialize}; @@ -10,7 +10,7 @@ use crate::GlobalAccountDataEvent; pub type IgnoredUserListEvent = GlobalAccountDataEvent; /// The payload for `IgnoredUserListEvent`. -#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] +#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.ignored_user_list")] pub struct IgnoredUserListEventContent { diff --git a/crates/ruma-events/src/key/verification/accept.rs b/crates/ruma-events/src/key/verification/accept.rs index 651e3fac..c8bff1da 100644 --- a/crates/ruma-events/src/key/verification/accept.rs +++ b/crates/ruma-events/src/key/verification/accept.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; -use ruma_events_macros::BasicEventContent; +use ruma_events_macros::EventContent; #[cfg(feature = "unstable-pre-spec")] use ruma_events_macros::MessageEventContent; use serde::{Deserialize, Serialize}; @@ -22,7 +22,7 @@ use crate::MessageEvent; pub type AcceptEvent = MessageEvent; /// The payload for a to-device `AcceptEvent`. -#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] +#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[ruma_event(type = "m.key.verification.accept")] pub struct AcceptToDeviceEventContent { /// An opaque identifier for the verification process. diff --git a/crates/ruma-events/src/key/verification/cancel.rs b/crates/ruma-events/src/key/verification/cancel.rs index d374275f..d2c530c0 100644 --- a/crates/ruma-events/src/key/verification/cancel.rs +++ b/crates/ruma-events/src/key/verification/cancel.rs @@ -1,6 +1,6 @@ //! Types for the *m.key.verification.cancel* event. -use ruma_events_macros::BasicEventContent; +use ruma_events_macros::EventContent; #[cfg(feature = "unstable-pre-spec")] use ruma_events_macros::MessageEventContent; use ruma_serde::StringEnum; @@ -17,7 +17,7 @@ use crate::MessageEvent; pub type CancelEvent = MessageEvent; /// The payload for a to-device `CancelEvent`. -#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] +#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[ruma_event(type = "m.key.verification.cancel")] pub struct CancelToDeviceEventContent { /// The opaque identifier for the verification process/request. diff --git a/crates/ruma-events/src/key/verification/key.rs b/crates/ruma-events/src/key/verification/key.rs index e132e914..b1c16055 100644 --- a/crates/ruma-events/src/key/verification/key.rs +++ b/crates/ruma-events/src/key/verification/key.rs @@ -1,6 +1,6 @@ //! Types for the *m.key.verification.key* event. -use ruma_events_macros::BasicEventContent; +use ruma_events_macros::EventContent; #[cfg(feature = "unstable-pre-spec")] use ruma_events_macros::MessageEventContent; use serde::{Deserialize, Serialize}; @@ -16,7 +16,7 @@ use crate::MessageEvent; pub type KeyEvent = MessageEvent; /// The payload for a to-device `KeyEvent`. -#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] +#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[ruma_event(type = "m.key.verification.key")] pub struct KeyToDeviceEventContent { /// An opaque identifier for the verification process. diff --git a/crates/ruma-events/src/key/verification/mac.rs b/crates/ruma-events/src/key/verification/mac.rs index a838b7c9..228c3dc1 100644 --- a/crates/ruma-events/src/key/verification/mac.rs +++ b/crates/ruma-events/src/key/verification/mac.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; -use ruma_events_macros::BasicEventContent; +use ruma_events_macros::EventContent; #[cfg(feature = "unstable-pre-spec")] use ruma_events_macros::MessageEventContent; use serde::{Deserialize, Serialize}; @@ -18,7 +18,7 @@ use crate::MessageEvent; pub type MacEvent = MessageEvent; /// The payload for a to-device `MacEvent`. -#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] +#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[ruma_event(type = "m.key.verification.mac")] pub struct MacToDeviceEventContent { /// An opaque identifier for the verification process. diff --git a/crates/ruma-events/src/key/verification/request.rs b/crates/ruma-events/src/key/verification/request.rs index cc37347f..2d375e8d 100644 --- a/crates/ruma-events/src/key/verification/request.rs +++ b/crates/ruma-events/src/key/verification/request.rs @@ -2,14 +2,14 @@ use std::time::SystemTime; -use ruma_events_macros::BasicEventContent; +use ruma_events_macros::EventContent; use ruma_identifiers::DeviceIdBox; use serde::{Deserialize, Serialize}; use super::VerificationMethod; /// The payload for `RequestEvent`. -#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] +#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[ruma_event(type = "m.key.verification.request")] pub struct RequestToDeviceEventContent { /// The device ID which is initiating the request. diff --git a/crates/ruma-events/src/key/verification/start.rs b/crates/ruma-events/src/key/verification/start.rs index 1612cdde..eccc7076 100644 --- a/crates/ruma-events/src/key/verification/start.rs +++ b/crates/ruma-events/src/key/verification/start.rs @@ -2,7 +2,7 @@ use std::{collections::BTreeMap, convert::TryFrom}; -use ruma_events_macros::BasicEventContent; +use ruma_events_macros::EventContent; #[cfg(feature = "unstable-pre-spec")] use ruma_events_macros::MessageEventContent; use ruma_identifiers::DeviceIdBox; @@ -24,7 +24,7 @@ use crate::MessageEvent; pub type StartEvent = MessageEvent; /// The payload of a to-device *m.key.verification.start* event. -#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] +#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[ruma_event(type = "m.key.verification.start")] pub struct StartToDeviceEventContent { /// The device ID which is initiating the process. diff --git a/crates/ruma-events/src/lib.rs b/crates/ruma-events/src/lib.rs index 92bdba1d..21232b7b 100644 --- a/crates/ruma-events/src/lib.rs +++ b/crates/ruma-events/src/lib.rs @@ -152,7 +152,7 @@ pub mod exports { /// Re-export of all the derives needed to create your own event types. pub mod macros { pub use ruma_events_macros::{ - BasicEventContent, EphemeralRoomEventContent, Event, MessageEventContent, StateEventContent, + EphemeralRoomEventContent, Event, MessageEventContent, StateEventContent, }; } diff --git a/crates/ruma-events/src/push_rules.rs b/crates/ruma-events/src/push_rules.rs index 229fd54a..ed86f5ec 100644 --- a/crates/ruma-events/src/push_rules.rs +++ b/crates/ruma-events/src/push_rules.rs @@ -1,7 +1,7 @@ //! Types for the *m.push_rules* event. use ruma_common::push::Ruleset; -use ruma_events_macros::BasicEventContent; +use ruma_events_macros::EventContent; use serde::{Deserialize, Serialize}; use crate::GlobalAccountDataEvent; @@ -10,7 +10,7 @@ use crate::GlobalAccountDataEvent; pub type PushRulesEvent = GlobalAccountDataEvent; /// The payload for `PushRulesEvent`. -#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] +#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[ruma_event(type = "m.push_rules")] pub struct PushRulesEventContent { /// The global ruleset. diff --git a/crates/ruma-events/src/room_key.rs b/crates/ruma-events/src/room_key.rs index ad66e26b..5e22d308 100644 --- a/crates/ruma-events/src/room_key.rs +++ b/crates/ruma-events/src/room_key.rs @@ -1,11 +1,11 @@ //! Types for the *m.room_key* event. -use ruma_events_macros::BasicEventContent; +use ruma_events_macros::EventContent; use ruma_identifiers::{EventEncryptionAlgorithm, RoomId}; use serde::{Deserialize, Serialize}; /// The payload for `RoomKeyEvent`. -#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] +#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[ruma_event(type = "m.room_key")] pub struct RoomKeyToDeviceEventContent { /// The encryption algorithm the key in this event is to be used with. diff --git a/crates/ruma-events/src/room_key_request.rs b/crates/ruma-events/src/room_key_request.rs index c0a7ca3f..c718b8fb 100644 --- a/crates/ruma-events/src/room_key_request.rs +++ b/crates/ruma-events/src/room_key_request.rs @@ -1,12 +1,12 @@ //! Types for the *m.room_key_request* event. -use ruma_events_macros::BasicEventContent; +use ruma_events_macros::EventContent; use ruma_identifiers::{DeviceIdBox, EventEncryptionAlgorithm, RoomId}; use ruma_serde::StringEnum; use serde::{Deserialize, Serialize}; /// The payload for `RoomKeyRequestEvent`. -#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] +#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[ruma_event(type = "m.room_key_request")] pub struct RoomKeyRequestToDeviceEventContent { /// Whether this is a new key request or a cancellation of a previous request. diff --git a/crates/ruma-events/src/tag.rs b/crates/ruma-events/src/tag.rs index 96d988ad..96d4133c 100644 --- a/crates/ruma-events/src/tag.rs +++ b/crates/ruma-events/src/tag.rs @@ -2,7 +2,7 @@ use std::{collections::BTreeMap, error::Error, fmt, str::FromStr}; -use ruma_events_macros::BasicEventContent; +use ruma_events_macros::EventContent; use ruma_serde::deserialize_cow_str; use serde::{Deserialize, Serialize}; @@ -15,7 +15,7 @@ pub type TagEvent = RoomAccountDataEvent; pub type Tags = BTreeMap; /// The payload for `TagEvent`. -#[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] +#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.tag")] pub struct TagEventContent {