[−][src]Trait eventually::aggregate::Aggregate
An Aggregate is an entity which State is composed of one or more Value-Objects, Entities or Aggregates.
State mutations are expressed through clear Domain Events which, if applied in the same order as they happened chronologically, will yield the same Aggregate State.
Associated Types
type State
State of the Aggregate.
Usually this associate type is either Self
, Option<Self>
or
Option<T>
, depending on whether the Aggregate state is defined
in a separate data structure or using the same structure that
implements this trait.
type Event
Domain events that express mutations of the Aggregate State.
An enum
containing all the possible domain events is the
usual reccomendation.
type Error
Error type returned in apply
when mutating the Aggregate State
to the next version fails.
Usually, this error is a validation error type raised when the domain event that is being applied is invalid, based on the current State.
Consider using std::convert::Infallible
(or !
type if using nightly)
if the apply
method doesn't fail.
Required methods
fn apply(
state: Self::State,
event: Self::Event
) -> Result<Self::State, Self::Error>
state: Self::State,
event: Self::Event
) -> Result<Self::State, Self::Error>
Applies the changes described by the domain event in Self::Event
to the current state
of the Aggregate
.
Provided methods
fn fold<I>(state: Self::State, events: I) -> Result<Self::State, Self::Error> where
I: Iterator<Item = Self::Event>,
I: Iterator<Item = Self::Event>,
Applies a stream of events to the current Aggregate
state, returning
the updated state or an error, if any such happened.
Implementors
impl<T: OptionalAggregate> Aggregate for eventually::aggregate::optional::AsAggregate<T>
[src]
type State = Option<T::State>
type Event = T::Event
type Error = T::Error
fn apply(
state: Self::State,
event: Self::Event
) -> Result<Self::State, Self::Error>
[src]
state: Self::State,
event: Self::Event
) -> Result<Self::State, Self::Error>