pub trait Aggregate:
Default
+ Send
+ Sync {
type Event: EventData;
// Required methods
fn stream_category() -> &'static str;
fn apply(&mut self, event: &Self::Event);
}Expand description
The domain model whose state is rebuilt by folding events.
Why Default? In event sourcing, an aggregate’s state is defined
by its event history. Default::default() represents the state
before any events have been applied — a logically empty aggregate.
All real state arises through apply. If your
aggregate has fields that look invalid in their default form (e.g.
BankAccount { open: false, owner: "".into() }), that’s correct —
those values are unreachable in practice because the first event
(e.g. Opened) will set them. Mire constructs the empty aggregate,
then replays events onto it.
If your apply implementation guards against operating on a default
aggregate (e.g. early-returns when !self.open), the invariants
hold even if someone accidentally calls a method on a Default::default()
instance — the events that would unlock real behaviour simply
haven’t been applied yet.
Required Associated Types§
Required Methods§
Sourcefn stream_category() -> &'static str
fn stream_category() -> &'static str
The category prefix for streams of this aggregate type. Streams
are identified as format!("{category}-{id}"); the category is
what ProjectionRunners subscribe to and what
EventStore::read_category_after filters on.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".