Skip to main content

Handle

Trait Handle 

Source
pub trait Handle<C>: Aggregate {
    // Required method
    fn handle(&self, command: &C) -> Result<Vec<Self::Event>, Self::Error>;
}
Expand description

Entry point for command handling.

Each command type gets its own implementation, letting the aggregate express validation logic in a strongly typed way.

impl Handle<DepositFunds> for Account {
    fn handle(&self, command: &DepositFunds) -> Result<Vec<Self::Event>, Self::Error> {
        if command.amount <= 0 {
            return Err("amount must be positive".into());
        }
        Ok(vec![FundsDeposited { amount: command.amount }.into()])
    }
}

Required Methods§

Source

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

Handle a command and produce events.

§Errors

Returns Self::Error if the command is invalid for the current aggregate 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§