diff --git a/crates/ruma-events/src/lib.rs b/crates/ruma-events/src/lib.rs index 99bc5f8c..d69560e7 100644 --- a/crates/ruma-events/src/lib.rs +++ b/crates/ruma-events/src/lib.rs @@ -363,6 +363,57 @@ pub trait RedactedMessageEventContent: RedactedEventContent {} /// Marker trait for the content of a redacted state event. pub trait RedactedStateEventContent: RedactedEventContent {} +/// Trait for abstracting over event content structs. +/// +/// … but *not* enums which don't always have an event type and kind (e.g. message vs state) that's +/// fixed / known at compile time. +pub trait StaticEventContent: EventContent { + /// The event's "kind". + /// + /// See the type's documentation. + const KIND: EventKind; + + /// The event type. + const TYPE: &'static str; +} + +/// The "kind" of an event. +/// +/// This corresponds directly to the event content marker traits. +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[non_exhaustive] +pub enum EventKind { + /// Global account data event kind. + GlobalAccountData, + + /// Room account data event kind. + RoomAccountData, + + /// Ephemeral room event kind. + EphemeralRoomData, + + /// Message event kind. + /// + /// Since redacted / non-redacted message events are used in the same places bu have different + /// sets of fields, these two variations are treated as two closely-related event kinds. + Message { + /// Redacted variation? + redacted: bool, + }, + + /// State event kind. + /// + /// Since redacted / non-redacted state events are used in the same places bu have different + /// sets of fields, these two variations are treated as two closely-related event kinds. + State { + /// Redacted variation? + redacted: bool, + }, + + /// To-device event kind. + ToDevice, +} + /// `HasDeserializeFields` is used in the code generated by the `Event` derive /// to aid in deserializing redacted events. #[doc(hidden)]