pub trait Aggregate: Default {
type Event;
type Error;
type Id;
const KIND: &'static str;
// Required method
fn apply(&mut self, event: &Self::Event);
}Expand description
Command-side entities that produce domain events.
Aggregates rebuild their state from events (Apply<E>) and validate
commands via Handle<C>. The derive macro generates the event enum and
plumbing automatically, while keeping your state struct focused on domain
behaviour.
Aggregates are domain objects and do not require serialisation by default.
If you enable snapshots (via Repository::with_snapshots), the aggregate
state must be serialisable (Serialize + DeserializeOwned).
Required Associated Constants§
Required Associated Types§
Required Methods§
Sourcefn apply(&mut self, event: &Self::Event)
fn apply(&mut self, event: &Self::Event)
Apply an event to update aggregate state.
This is called during event replay to rebuild aggregate state from history.
When using #[derive(Aggregate)], this dispatches to your Apply<E>
implementations. For hand-written aggregates, implement this
directly with a match expression.
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.