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 stepContext: Shared dependencies (injected, not passed between steps)Error: The error type for step failures
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn compensate(
&self,
ctx: &Self::Context,
input: Self::Input,
) -> Result<(), Self::Error>
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.
Sourcefn compensation_description(&self) -> String
fn compensation_description(&self) -> String
Human-readable description of what compensation will do.