bus_core/event.rs
1use crate::id::MessageId;
2use serde::{Serialize, de::DeserializeOwned};
3use std::borrow::Cow;
4
5/// Marker trait for all events published through the event bus.
6///
7/// Implement manually or use `#[derive(Event)]` from the `bus-macros` crate.
8/// Every implementor must have a stable, unique `message_id()` for idempotency
9/// and deduplication.
10pub trait Event: Serialize + DeserializeOwned + Send + Sync + 'static {
11 /// NATS subject for this event.
12 fn subject(&self) -> Cow<'_, str>;
13
14 /// Unique identifier used as the message ID header and idempotency key.
15 fn message_id(&self) -> MessageId;
16
17 /// Aggregate type used for outbox routing.
18 fn aggregate_type() -> &'static str
19 where
20 Self: Sized,
21 {
22 "default"
23 }
24}