pub enum IdempotencyStrategy<P> {
Provided,
Custom(IdempotencyDeriver<P>),
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(IdempotencyDeriver<P>)
Derives the token by applying the given callback to the event about to
be written. See IdempotencyDeriver.
Prefer constructing this variant via
IdempotencyStrategy::custom so the Arc wrapping stays an
implementation detail.
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 custom<F>(f: F) -> Self
pub fn custom<F>(f: F) -> Self
Builds an IdempotencyStrategy::Custom from a callback without
requiring the caller to wrap it in Arc.
§Example
use outbox_core::prelude::*;
let strategy: IdempotencyStrategy<MyEvent> =
IdempotencyStrategy::custom(|event| event.id.as_uuid().to_string());Source§impl<P> IdempotencyStrategy<P>
impl<P> IdempotencyStrategy<P>
Sourcepub fn invoke(
&self,
provided_token: Option<String>,
event: &Event<P>,
) -> Option<String>
pub fn invoke( &self, provided_token: Option<String>, event: &Event<P>, ) -> 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— passeseventto the user-supplied callback and wraps the returnedStringinSome.None— returnsNone; neitherprovided_tokennoreventis used.
Trait Implementations§
Source§impl<P: Clone> Clone for IdempotencyStrategy<P>
impl<P: Clone> Clone for IdempotencyStrategy<P>
Source§fn clone(&self) -> IdempotencyStrategy<P>
fn clone(&self) -> IdempotencyStrategy<P>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more