events: Remove BasicEventContent trait and derive

This commit is contained in:
Kévin Commaille 2021-05-10 17:59:55 +02:00 committed by Jonas Platte
parent 7faa59be6b
commit 0acb121ee5
21 changed files with 38 additions and 73 deletions

View File

@ -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<TokenStream> {
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,

View File

@ -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(),
}
}

View File

@ -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 {

View File

@ -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:

View File

@ -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<DirectEventContent>;
///
/// 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<UserId, Vec<RoomId>>);

View File

@ -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 {}

View File

@ -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<C: BasicEventContent> {
pub struct GlobalAccountDataEvent<C: EventContent> {
/// Data specific to the event type.
pub content: C,
}
/// A room account data event.
#[derive(Clone, Debug, Event)]
pub struct RoomAccountDataEvent<C: BasicEventContent> {
pub struct RoomAccountDataEvent<C: EventContent> {
/// Data specific to the event type.
pub content: C,
}

View File

@ -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 {

View File

@ -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<FullyReadEventContent>;
/// 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.

View File

@ -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<IgnoredUserListEventContent>;
/// 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 {

View File

@ -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<AcceptEventContent>;
/// 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.

View File

@ -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<CancelEventContent>;
/// 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.

View File

@ -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<KeyEventContent>;
/// 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.

View File

@ -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<MacEventContent>;
/// 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.

View File

@ -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.

View File

@ -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<StartEventContent>;
/// 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.

View File

@ -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,
};
}

View File

@ -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<PushRulesEventContent>;
/// 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.

View File

@ -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.

View File

@ -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.

View File

@ -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<TagEventContent>;
pub type Tags = BTreeMap<TagName, TagInfo>;
/// 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 {