Aggregate

Trait Aggregate 

Source
pub trait Aggregate {
    type Id: Eq;
    type State: Default;
    type Event;
    type Command;
    type Error;

    // Required methods
    fn apply(
        state: Self::State,
        event: Self::Event,
    ) -> Result<Self::State, Self::Error>;
    fn handle<'a, 's: 'a>(
        &'a self,
        id: &'s Self::Id,
        state: &'s Self::State,
        command: Self::Command,
    ) -> BoxFuture<'a, Result<Option<Vec<Self::Event>>, Self::Error>>
       where Self: Sized;
}
Expand description

An Aggregate manages a domain entity State, acting as a transaction boundary.

It allows state mutations through the use of Commands, which the Aggregate instance handles and emits a number of Domain Events.

Required Associated Types§

Source

type Id: Eq

Aggregate identifier: this should represent an unique identifier to refer to a unique Aggregate instance.

Source

type State: Default

State of the Aggregate: this should represent the Domain Entity data structure.

Source

type Event

Represents a specific, domain-related change to the Aggregate State.

Source

type Command

Commands are all the possible operations available on an Aggregate. Use Commands to model business use-cases or State mutations.

Source

type Error

Possible failures while applying Events or handling Commands.

Required Methods§

Source

fn apply( state: Self::State, event: Self::Event, ) -> Result<Self::State, Self::Error>

Applies an Event to the current Aggregate State.

To enforce immutability, this method takes ownership of the previous State and the current Event to apply, and returns the new version of the State or an error.

Source

fn handle<'a, 's: 'a>( &'a self, id: &'s Self::Id, state: &'s Self::State, command: Self::Command, ) -> BoxFuture<'a, Result<Option<Vec<Self::Event>>, Self::Error>>
where Self: Sized,

Handles the requested Command and returns a list of Events to apply the State mutation based on the current representation of the State.

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§