ruma_macros

Macro event_enum

Source
event_enum!() { /* proc-macro */ }
Expand description

Generates an enum to represent the various Matrix event types.

This macro also implements the necessary traits for the type to serialize and deserialize itself.

By default, the types generated by this macro get a #[non_exhaustive] attribute. This behavior can be controlled by setting the ruma_unstable_exhaustive_types compile-time cfg setting as --cfg=ruma_unstable_exhaustive_types using RUSTFLAGS or .cargo/config.toml (under [build] -> rustflags = ["..."]). When that setting is activated, the attribute is not applied so the types are exhaustive.

§Examples

use ruma_macros::event_enum;

event_enum! {
    enum ToDevice {
        "m.any.event",
        "m.other.event",
    }

    enum State {
        "m.more.events",
        "m.different.event",
    }
}

(The enum name has to be a valid identifier for <EventKind as Parse>::parse)