Skip to main content

Event

Derive Macro Event 

Source
#[derive(Event)]
Expand description

Derive macro for multi-event enums that generates automatic event dispatch.

This macro generates:

  • {EnumName}Publisher struct implementing AsyncEventPublisher and EventPublisher
  • PublishableEvent and AsyncPublishableEvent trait implementations
  • From<VariantType> impls for each variant

Each variant is forwarded to its underlying event channel when published.

Note: You cannot subscribe to wrapper enums directly. Subscribe to the individual concrete event types (e.g., BatteryEvent, PointingEvent) instead.

§Example

#[derive(Event)]
pub enum MultiSensorEvent {
    Battery(BatteryEvent),
    Pointing(PointingEvent),
}

// Publishing: events are routed to their concrete type channels
publish_event_async(MultiSensorEvent::Battery(event)).await;