Trait thalo::Handle

source ·
pub trait Handle<C>: Aggregate {
    type Error: Display;

    // Required method
    fn handle(
        cmd: C
    ) -> Result<Vec<<Self as Aggregate>::Event>, Self::Error>;
Expand description

Handles a command, returning events.

Commands use the aggregates state to validate business rules, and returns events which are later used to update the aggregate state.


use thalo::{events, Handle};

pub struct Increment {
    pub amount: u64,

impl Handle<Increment> for Counter {
    type Error = &'static str;

    fn handle(&self, cmd: Increment) -> Result<Vec<CounterEvent>, Self::Error> {
        if self.count + cmd.amount > 100_000 {
            return Err("count would be too high");
        events![ Incremented { amount: cmd.amount } ]

Required Associated Types§

Required Methods§


fn handle(&self, cmd: C) -> Result<Vec<<Self as Aggregate>::Event>, Self::Error>

Object Safety§

This trait is not object safe.