pub trait Handler<P: 'static>: Sync + Send {
// Required methods
fn handle<'a>(
&'a self,
projection: &'a mut P,
event: &'a Event,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>;
fn aggregator_type(&self) -> &'static str;
fn event_name(&self) -> &'static str;
}Expand description
Trait for event handlers.
Handlers process events in two modes:
handle: For subscriptions that perform side effects (send emails, update read models)apply: For loading aggregate state by replaying events
This trait is typically implemented via the #[evento::handler] macro.
Required Methods§
Sourcefn handle<'a>(
&'a self,
projection: &'a mut P,
event: &'a Event,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>
fn handle<'a>( &'a self, projection: &'a mut P, event: &'a Event, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>
Applies an event to build projection state.
This is called when loading aggregate state by replaying events. It should be a pure function that modifies the projection without side effects.
Sourcefn aggregator_type(&self) -> &'static str
fn aggregator_type(&self) -> &'static str
Returns the aggregator type this handler processes.
Sourcefn event_name(&self) -> &'static str
fn event_name(&self) -> &'static str
Returns the event name this handler processes.