[−][src]Macro ruma_events_macros::ruma_event
ruma_event!() { /* proc-macro */ }
Generates a Rust type for a Matrix event.
Examples
The most common form of event is a struct with all the standard fields for an event of its
kind and a struct for its content
field:
ruma_event! { /// Informs the room about what room aliases it has been given. AliasesEvent { kind: StateEvent, event_type: RoomAliases, content: { /// A list of room aliases. pub aliases: Vec<ruma_identifiers::RoomAliasId>, } } }
Occasionally an event will have non-standard fields at its top level (outside the content
field). These extra fields are declared in block labeled with fields
:
ruma_event! { /// A redaction of an event. RedactionEvent { kind: RoomEvent, event_type: RoomRedaction, fields: { /// The ID of the event that was redacted. pub redacts: ruma_identifiers::EventId }, content: { /// The reason for the redaction, if any. pub reason: Option<String>, }, } }
Sometimes the type of the content
should be a type alias rather than a struct or enum. This
is designated with content_type_alias
:
ruma_event! { /// Informs the client about the rooms that are considered direct by a user. DirectEvent { kind: Event, event_type: Direct, content_type_alias: { /// The payload of a `DirectEvent`. /// /// A mapping of `UserId`'s to a collection of `RoomId`'s which are considered /// *direct* for that particular user. std::collections::BTreeMap<ruma_identifiers::UserId, Vec<ruma_identifiers::RoomId>> } } }
If content
and content_type_alias
are both supplied, the second one listed will overwrite
the first.
The event type and content type will have copies generated inside a private raw
module. These
"raw" versions are the same, except they implement serde::Deserialize
. An implementation of
FromRaw
will be provided, which will allow the user to deserialize the event type as
EventJson<EventType>
.