Aggregate

Trait Aggregate 

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

    // Required methods
    fn apply_first(event: Self::Event) -> Result<Self::State, Self::Error>;
    fn apply_next(
        state: Self::State,
        event: Self::Event,
    ) -> Result<Self::State, Self::Error>;
    fn handle_first<'s, 'a>(
        &'s self,
        id: &'a Self::Id,
        command: Self::Command,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<Self::Event>>, Self::Error>> + Send + 's>>
       where 'a: 's,
             Self: Sized;
    fn handle_next<'a, 's>(
        &'a self,
        id: &'a Self::Id,
        state: &'s Self::State,
        command: Self::Command,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<Self::Event>>, Self::Error>> + Send + 'a>>
       where 's: 'a,
             Self: Sized;

    // Provided method
    fn as_aggregate(self) -> AsAggregate<Self>
       where Self: Sized { ... }
}
Expand description

An Option-flavoured, Aggregate-compatible trait to model Aggregates having an optional State.

Use as_aggregate to get an Aggregate-compatible instance of this trait.

Required Associated Types§

Source

type Id: Eq

Identifier type of the Aggregate.

Check out Aggregate::Id for more information.

Source

type State

State of the Aggregate.

Check out Aggregate::State for more information.

Source

type Event

Events produced and supported by the Aggregate.

Check out Aggregate::Event for more information.

Source

type Command

Commands supported by the Aggregate.

Check out Aggregate::Command for more information.

Source

type Error

Error produced by the the Aggregate while applying Events or handling Commands.

Required Methods§

Source

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

Applies the specified Event when the State is empty.

Source

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

Applies the specified Event on a pre-existing State value.

Source

fn handle_first<'s, 'a>( &'s self, id: &'a Self::Id, command: Self::Command, ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<Self::Event>>, Self::Error>> + Send + 's>>
where 'a: 's, Self: Sized,

Handles the specified Command when the State is empty.

Source

fn handle_next<'a, 's>( &'a self, id: &'a Self::Id, state: &'s Self::State, command: Self::Command, ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<Self::Event>>, Self::Error>> + Send + 'a>>
where 's: 'a, Self: Sized,

Handles the specified Command on a pre-existing State value.

Provided Methods§

Source

fn as_aggregate(self) -> AsAggregate<Self>
where Self: Sized,

Translates the current optional::Aggregate instance into a newtype instance compatible with the core Aggregate trait.

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§