Skip to main content

IdempotencyStore

Trait IdempotencyStore 

Source
pub trait IdempotencyStore {
    // Required methods
    fn get(&self, key: &IdempotencyKey) -> Option<LifecycleReceipt>;
    fn put(
        &self,
        key: &IdempotencyKey,
        receipt: &LifecycleReceipt,
    ) -> Result<StoreOutcome, ReceiptError>;
}
Expand description

Replay-boundary store. Distinct trait so a consumer can plug in a real database without this module knowing.

“Receipt content” for the replay comparison is the set of idempotency-invariant fields: every field except receipt_id, at_epoch_s, and sequence, which are minted fresh on each emission. Implementations MUST compare on that content (the in-memory implementation below is the reference shape) so a spec-compliant retry of the same idempotency_key replays rather than conflicting.

Required Methods§

Source

fn get(&self, key: &IdempotencyKey) -> Option<LifecycleReceipt>

Look up the prior receipt for key, if any.

Source

fn put( &self, key: &IdempotencyKey, receipt: &LifecycleReceipt, ) -> Result<StoreOutcome, ReceiptError>

Insert or replay-confirm receipt under key. Implementations must enforce the spec’s idempotency rule (comparing the idempotency-invariant content defined above, not the per-emission receipt_id/at_epoch_s/sequence):

  • if no prior entry exists → insert and return Ok(StoreOutcome::Inserted);
  • if a prior entry exists with content equal to receipt → return Ok(StoreOutcome::Replayed(prior)) without overwriting;
  • if a prior entry exists with different content → return Err(ReceiptError::Conflict { .. }).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§