AggregateRoot

Trait AggregateRoot 

Source
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§

Source

fn new(id: AggregateId) -> Self

Create new aggregate with given ID

Source

fn id(&self) -> &AggregateId

Get aggregate ID

Source

fn sequence(&self) -> EventSequence

Get current sequence number

Source

fn apply_event(&mut self, event: &DomainEvent) -> Result<()>

Apply an event to the aggregate

Source

fn uncommitted_events(&self) -> Vec<DomainEvent>

Get uncommitted events

Source

fn mark_events_committed(&mut self)

Mark events as committed

Source

fn create_snapshot(&self) -> Result<AggregateSnapshot>

Create snapshot of current state

Source

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.

Implementors§