pub trait EventBus {
type Event;
// Required methods
async fn publish(&self, event: Self::Event) -> Result<()>;
async fn next_event(&mut self) -> Result<Option<Self::Event>>;
}Expand description
A typed publish/subscribe channel carrying events of a single type.
Producers such as sensors and transports publish events, and consumers await them. The event type is fixed per bus so that delivery is statically typed.
Required Associated Types§
Required Methods§
Sourceasync fn publish(&self, event: Self::Event) -> Result<()>
async fn publish(&self, event: Self::Event) -> Result<()>
Publishes an event to every current subscriber.
§Arguments
event- the event to broadcast, consumed by the call.
§Returns
Ok(()) once the event has been accepted for delivery.
§Errors
Returns Error::Closed if the bus has been shut
down.
Sourceasync fn next_event(&mut self) -> Result<Option<Self::Event>>
async fn next_event(&mut self) -> Result<Option<Self::Event>>
Awaits the next event for this subscriber.
§Returns
Some(event) when an event is available, or None once the bus is closed.
§Errors
Returns Error::Closed if the bus has been shut
down unexpectedly.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".