Skip to main content

SagaStep

Trait SagaStep 

Source
pub trait SagaStep: Send + Sync {
    type Input: Clone + Send + 'static;
    type Output: Clone + Send + 'static;
    type Context;
    type Error;

    // Required methods
    fn name(&self) -> &'static str;
    fn execute(
        &self,
        ctx: &Self::Context,
        input: Self::Input,
    ) -> Result<Self::Output, Self::Error>;

    // Provided methods
    fn compensate(
        &self,
        ctx: &Self::Context,
        input: Self::Input,
    ) -> Result<(), Self::Error> { ... }
    fn compensation_description(&self) -> String { ... }
}
Expand description

A step in a saga that can be executed and compensated.

Each step transforms an input into an output, with the ability to undo its effects if a later step fails. The input is stored for compensation.

§Type Parameters

  • Input: Data received from the previous step (or saga entry point)
  • Output: Data produced for the next step
  • Context: Shared dependencies (injected, not passed between steps)
  • Error: The error type for step failures

Required Associated Types§

Source

type Input: Clone + Send + 'static

Data received from the previous step or saga entry point.

Source

type Output: Clone + Send + 'static

Data produced for the next step.

Source

type Context

Shared context providing dependencies.

Source

type Error

Error type for step failures.

Required Methods§

Source

fn name(&self) -> &'static str

Human-readable name for logging and error messages.

Source

fn execute( &self, ctx: &Self::Context, input: Self::Input, ) -> Result<Self::Output, Self::Error>

Execute the step, transforming input into output.

§Errors

Returns an error if the step fails to complete.

Provided Methods§

Source

fn compensate( &self, ctx: &Self::Context, input: Self::Input, ) -> Result<(), Self::Error>

Compensate (undo) the step’s effects.

Called during rollback when a later step fails. Receives the original input that was passed to execute().

The default implementation is a no-op, suitable for read-only steps.

§Errors

Returns an error if compensation fails.

Source

fn compensation_description(&self) -> String

Human-readable description of what compensation will do.

Implementors§