pub trait AggregateRoot {
// Required methods
fn new(id: AggregateId) -> Self;
fn id(&self) -> &AggregateId;
fn sequence(&self) -> EventSequence;
fn apply_event(&mut self, event: &DomainEvent) -> Result<()>;
fn uncommitted_events(&self) -> Vec<DomainEvent>;
fn mark_events_committed(&mut self);
fn create_snapshot(&self) -> Result<AggregateSnapshot>;
fn from_snapshot(snapshot: AggregateSnapshot) -> Result<Self>
where Self: Sized;
}Expand description
Trait for aggregate roots in event sourcing
Required Methods§
Sourcefn new(id: AggregateId) -> Self
fn new(id: AggregateId) -> Self
Create new aggregate with given ID
Sourcefn id(&self) -> &AggregateId
fn id(&self) -> &AggregateId
Get aggregate ID
Sourcefn sequence(&self) -> EventSequence
fn sequence(&self) -> EventSequence
Get current sequence number
Sourcefn apply_event(&mut self, event: &DomainEvent) -> Result<()>
fn apply_event(&mut self, event: &DomainEvent) -> Result<()>
Apply an event to the aggregate
Sourcefn uncommitted_events(&self) -> Vec<DomainEvent>
fn uncommitted_events(&self) -> Vec<DomainEvent>
Get uncommitted events
Sourcefn mark_events_committed(&mut self)
fn mark_events_committed(&mut self)
Mark events as committed
Sourcefn create_snapshot(&self) -> Result<AggregateSnapshot>
fn create_snapshot(&self) -> Result<AggregateSnapshot>
Create snapshot of current state
Sourcefn from_snapshot(snapshot: AggregateSnapshot) -> Result<Self>where
Self: Sized,
fn from_snapshot(snapshot: AggregateSnapshot) -> Result<Self>where
Self: Sized,
Restore from snapshot
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.