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 moreAuto Trait Implementations§
impl<P> !RefUnwindSafe for IdempotencyStrategy<P>
impl<P> !UnwindSafe for IdempotencyStrategy<P>
impl<P> Freeze for IdempotencyStrategy<P>
impl<P> Send for IdempotencyStrategy<P>
impl<P> Sync for IdempotencyStrategy<P>
impl<P> Unpin for IdempotencyStrategy<P>
impl<P> UnsafeUnpin for IdempotencyStrategy<P>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more