pub enum IdempotencyStrategy<P>{
Provided,
Custom(fn(&Event<P>) -> String),
Uuid,
None,
}Expand description
How an idempotency token is produced when a new event is written.
The variant is evaluated inside
OutboxService::add_event
before the event is persisted. When an
IdempotencyStorageProvider
is wired, the produced token is also used to reserve uniqueness up front.
Variants§
Provided
Uses the caller-supplied token as-is. Passing None at call site means
the event is stored without a token and no reservation is attempted.
Custom(fn(&Event<P>) -> String)
Derives the token by applying the given function to the event about to
be written. The add_event callback get_event must return Some
for this variant — otherwise the service panics.
Uuid
Generates a fresh UUID v7 token at write time. Any caller-supplied token is ignored.
None
Disables idempotency — no token is produced and no reservation is attempted. This is the default.
Implementations§
Source§impl<P> IdempotencyStrategy<P>
impl<P> IdempotencyStrategy<P>
Sourcepub fn invoke<F>(
&self,
provided_token: Option<String>,
get_event: F,
) -> Option<String>
pub fn invoke<F>( &self, provided_token: Option<String>, get_event: F, ) -> Option<String>
Resolves the strategy into a concrete token for the event about to be written.
Behaviour per variant:
Provided— returnsprovided_tokenas-is;Nonepropagates through and means the event will be stored without a token.Uuid— generates a fresh UUID v7;provided_tokenis ignored.Custom— invokesget_event, passes the resultingEventto the user-supplied function, and wraps the returnedStringinSome.None— returnsNone; neitherprovided_tokennorget_eventis used.
get_event is only evaluated for the Custom branch, so callers can
pass || None for every other strategy.
§Panics
Panics if the strategy is set to Custom, but the provided get_event
closure returns None. The panic message is
"Strategy is Custom, but no Event context provided".