#[derive(Aggregate)]
{
// Attributes available to this derive:
#[aggregate]
}
Expand description
Derives the Aggregate trait for a struct.
This macro generates:
- An event enum containing all aggregate event types
EventKindtrait implementation for runtime kind dispatchProjectionEventtrait implementation for event deserialisationFrom<E>implementations for each event typeAggregatetrait implementation that dispatches toApply<E>for events
Note: Commands are handled via individual Handle<C> trait
implementations. No command enum is generated - use
execute_command::<Aggregate, Command>() directly.
§Attributes
§Required
id = Type- Aggregate ID typeerror = Type- Error type for command handlingevents(Type1, Type2, ...)- Event types
§Optional
kind = "name"- Aggregate type identifier (default: lowercase struct name)event_enum = "Name"- Override generated event enum name (default:{Struct}Event)derives(Trait1, Trait2, ...)- Additional derives for the generated event enum. Always includesCloneandserde::Serialize. Common additions:Debug,PartialEq,Eq
§Example
ⓘ
#[derive(Aggregate)]
#[aggregate(
id = String,
error = String,
events(FundsDeposited, FundsWithdrawn),
derives(Debug, PartialEq, Eq)
)]
pub struct Account {
balance: i64,
}