pub trait Topic<E: Event>:
Hash
+ PartialEq
+ Eq
+ Clone
+ Send
+ Sync
+ 'static {
// Required method
fn from_event(event: &E) -> Self
where Self: Sized;
}Expand description
Maps events to routing topics.
Implement this for your own topic type (usually an enum) to classify events for the broker. Actors subscribe to one or more topics, and the broker delivers events to matching subscribers.
Topics must be Send + 'static because they are stored in the broker
which runs in a spawned task.
Common patterns:
- Enum topics for simple classification.
- Struct topics when you need richer metadata (e.g., names or IDs).
Trait bounds: refer to the event trait as crate::Event in generic
signatures to avoid confusion with the Event derive macro.
Required Methods§
fn from_event(event: &E) -> Selfwhere
Self: Sized,
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.