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§
type Event: Send + Clone + 'static
type Command: Send + 'static
type State: Default + Send + 'static
type Error: Error + Send + 'static
Required Methods§
Sourcefn correlation_id(event: &Self::Event) -> Option<String>
fn correlation_id(event: &Self::Event) -> Option<String>
Stable correlation key for event. None means the event is
not for this saga.
Sourcefn 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,
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§
Sourcefn encode_state(_state: &Self::State) -> Option<Result<Vec<u8>, String>>
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.
Sourcefn decode_state(_bytes: &[u8]) -> Result<Self::State, String>
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.