pub struct SagaBuilder<Input, Output, Ctx, Err, State> { /* private fields */ }Expand description
Type-state builder for constructing type-safe sagas.
The builder enforces at compile-time that:
- Each step’s input type matches the previous step’s output type
- The saga’s input type matches the first step’s input
- The saga’s output type matches the last step’s output
§Compile-time Type Safety
The builder ensures type safety at compile time. Mismatched types will not compile:
ⓘ
use changeset_saga::{SagaBuilder, SagaStep};
struct StepA;
impl SagaStep for StepA {
type Input = i32;
type Output = String; // Outputs String
type Context = ();
type Error = ();
fn name(&self) -> &'static str { "a" }
fn execute(&self, _: &(), input: i32) -> Result<String, ()> {
Ok(input.to_string())
}
}
struct StepB;
impl SagaStep for StepB {
type Input = i32; // Expects i32, not String!
type Output = i32;
type Context = ();
type Error = ();
fn name(&self) -> &'static str { "b" }
fn execute(&self, _: &(), input: i32) -> Result<i32, ()> {
Ok(input * 2)
}
}
// This should fail: StepB expects i32 but StepA outputs String
let saga = SagaBuilder::new()
.first_step(StepA)
.then(StepB) // Compile error here!
.build();An empty saga (without calling first_step()) cannot be built:
ⓘ
use changeset_saga::SagaBuilder;
// Cannot build an empty saga - `build()` is only available after `first_step()`
let saga = SagaBuilder::<(), (), (), ()>::new().build();Implementations§
Source§impl<Ctx, Err> SagaBuilder<(), (), Ctx, Err, Empty>
impl<Ctx, Err> SagaBuilder<(), (), Ctx, Err, Empty>
Source§impl<Ctx, Err> SagaBuilder<(), (), Ctx, Err, Empty>
impl<Ctx, Err> SagaBuilder<(), (), Ctx, Err, Empty>
Sourcepub fn first_step<S>(
self,
step: S,
) -> SagaBuilder<S::Input, S::Output, Ctx, Err, HasSteps<S::Output>>where
S: SagaStep<Context = Ctx, Error = Err> + 'static,
pub fn first_step<S>(
self,
step: S,
) -> SagaBuilder<S::Input, S::Output, Ctx, Err, HasSteps<S::Output>>where
S: SagaStep<Context = Ctx, Error = Err> + 'static,
Add the first step to the saga.
This establishes the saga’s input type from the step’s input type.
Source§impl<Input, CurrentOutput, Ctx, Err> SagaBuilder<Input, CurrentOutput, Ctx, Err, HasSteps<CurrentOutput>>
impl<Input, CurrentOutput, Ctx, Err> SagaBuilder<Input, CurrentOutput, Ctx, Err, HasSteps<CurrentOutput>>
Trait Implementations§
Auto Trait Implementations§
impl<Input, Output, Ctx, Err, State> Freeze for SagaBuilder<Input, Output, Ctx, Err, State>
impl<Input, Output, Ctx, Err, State> !RefUnwindSafe for SagaBuilder<Input, Output, Ctx, Err, State>
impl<Input, Output, Ctx, Err, State> !Send for SagaBuilder<Input, Output, Ctx, Err, State>
impl<Input, Output, Ctx, Err, State> !Sync for SagaBuilder<Input, Output, Ctx, Err, State>
impl<Input, Output, Ctx, Err, State> Unpin for SagaBuilder<Input, Output, Ctx, Err, State>
impl<Input, Output, Ctx, Err, State> UnsafeUnpin for SagaBuilder<Input, Output, Ctx, Err, State>
impl<Input, Output, Ctx, Err, State> !UnwindSafe for SagaBuilder<Input, Output, Ctx, Err, State>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more