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.

Implementations MUST be content-equality stable: a get after put(k, v) returns a value equal (by LifecycleReceipt::eq) to v. The in-memory implementation below is the reference shape.

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:

  • 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 { .. }).

Implementors§