Derive Macro Event
#[derive(Event)]
{
// Attributes available to this derive:
#[subject]
}
Expand description
Derive macro that implements arminius_lib_message_bus::Event.
§Attributes
#[subject(...)] — the NATS subject the event is published on. Supported
forms:
#[subject("MyEvent.v1")]#[subject(name = "MyEvent", version = "1")]#[subject(name = "MyEvent", version("1"))]#[subject(name = "MyEvent", version = env!("CARGO_PKG_VERSION_MAJOR"))]#[subject(name = "MyEvent", version(env!("CARGO_PKG_VERSION_MAJOR")))]#[subject(name = "MyEvent", version = "2", compatible = [v0::MyEvent])]#[subject(version = env!("CARGO_PKG_VERSION_MAJOR"))]#[subject(version = "2", compatible = [v1::MyEvent, v0::MyEvent])]
§Subject rules
- Struct-name fallback. When
nameis omitted the struct name is used. compatiblelist. Names older event types whose subjects the subscriber will also consume, converting each toSelfvia the requiredFrom<OldType> for Selfimplementation.
§Dynamic (per-instance) subjects
The subject template (the string literal, or the name value) may embed
{field} placeholders naming struct fields. The generated
Event::SUBJECT constant replaces each placeholder with a * wildcard
(used to subscribe / as the stream filter), while the generated
subject(&self) method interpolates each field’s Display value to build
the concrete subject the instance publishes to. Multiple placeholders map to
one * each, in order; with no placeholders subject(&self) equals
SUBJECT.
ⓘ
// SUBJECT == "rooms.*.events.v1"
// RoomCreated { room_id: 7, .. }.subject() == "rooms.7.events.v1"
#[derive(Event)]
#[subject(name = "rooms.{room_id}.events", version = 1)]
struct RoomCreated {
room_id: u64,
}