Skip to main content

mnesis_store/
conflict.rs

1//! Shared optimistic-concurrency conflict predicate.
2//!
3//! Moved out of `saga.rs` so both [`SagaError`](crate::SagaError) and
4//! `ExecuteError` delegate to the same
5//! [`StoreError::is_conflict`](crate::StoreError::is_conflict) — one truth,
6//! two callers.
7
8use crate::error::StoreError;
9
10mod sealed {
11    pub trait Sealed {}
12}
13
14/// Predicate over a repository error: is this an optimistic-concurrency
15/// conflict (and therefore retryable by reloading + re-deciding)?
16///
17/// Sealed: implemented inside this crate for [`StoreError`] only. Lets error
18/// wrappers delegate without naming a concrete store error — `Snapshotting`'s
19/// `Repository::Error` is the inner `StoreError`, so one impl serves bare and
20/// snapshotted repositories alike.
21pub trait ConflictPredicate: sealed::Sealed {
22    /// `true` iff this error is an optimistic-concurrency conflict.
23    fn is_conflict(&self) -> bool;
24}
25
26impl<A, EncErr, DecErr> sealed::Sealed for StoreError<A, EncErr, DecErr> {}
27
28impl<A, EncErr, DecErr> ConflictPredicate for StoreError<A, EncErr, DecErr> {
29    fn is_conflict(&self) -> bool {
30        Self::is_conflict(self)
31    }
32}