Skip to main content

Saga

Trait Saga 

Source
pub trait Saga: Send + 'static {
    type Event: Send + Clone + 'static;
    type Command: Send + 'static;
    type State: Default + Send + 'static;
    type Error: Error + Send + 'static;

    // Required methods
    fn correlation_id(event: &Self::Event) -> Option<String>;
    fn handle<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        state: &'life1 mut Self::State,
        event: Self::Event,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<SagaAction<Self::Command>>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn encode_state(_state: &Self::State) -> Option<Result<Vec<u8>, String>> { ... }
    fn decode_state(_bytes: &[u8]) -> Result<Self::State, String> { ... }
}
Expand description

User-defined saga / process manager.

Required Associated Types§

Source

type Event: Send + Clone + 'static

Source

type Command: Send + 'static

Source

type State: Default + Send + 'static

Source

type Error: Error + Send + 'static

Required Methods§

Source

fn correlation_id(event: &Self::Event) -> Option<String>

Stable correlation key for event. None means the event is not for this saga.

Source

fn handle<'life0, 'life1, 'async_trait>( &'life0 mut self, state: &'life1 mut Self::State, event: Self::Event, ) -> Pin<Box<dyn Future<Output = Result<Vec<SagaAction<Self::Command>>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

React to an event. Receives mutable access to the per-saga state keyed by correlation_id.

Provided Methods§

Source

fn encode_state(_state: &Self::State) -> Option<Result<Vec<u8>, String>>

Optional codec for state persistence. None keeps state in-memory only (default — preserves v1 behavior). Implement to participate in crate::saga::SagaStateStore persistence.

Source

fn decode_state(_bytes: &[u8]) -> Result<Self::State, String>

Decode a persisted payload back into State. Required iff Self::encode_state is implemented.

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§