pub struct DiffStore {
inner: RwLock<HashMap<DiffId, DiffRecord>>,
ttl_secs: i64,
}Expand description
In-memory store for pending diff records.
Backed by a RwLock<HashMap> so reads (polling, rendering the modal) are
non-blocking. Mutations take a write lock.
The store is intentionally not persisted to disk — if the app restarts, pending diffs are lost and the user must start the flow again.
Fields§
§inner: RwLock<HashMap<DiffId, DiffRecord>>§ttl_secs: i64Implementations§
Source§impl DiffStore
impl DiffStore
Sourcepub fn with_ttl(ttl_secs: i64) -> Self
pub fn with_ttl(ttl_secs: i64) -> Self
Create a store with a custom TTL (useful in tests with a mock clock).
Sourcefn now_secs() -> i64
fn now_secs() -> i64
Return current Unix time in seconds.
Using SystemTime directly. Test overrides pass explicit timestamps
through the create_at parameter variant.
Sourcepub fn create(&self, payload: DiffPayload) -> DiffId
pub fn create(&self, payload: DiffPayload) -> DiffId
Create a new diff record and return its DiffId.
The record starts in DiffStatus::Pending.
Sourcepub fn create_at(&self, payload: DiffPayload, now: i64) -> DiffId
pub fn create_at(&self, payload: DiffPayload, now: i64) -> DiffId
Create a diff record at an explicit timestamp (test helper).
Sourcepub fn cancel(&self, id: &DiffId) -> Result<(), AppError>
pub fn cancel(&self, id: &DiffId) -> Result<(), AppError>
Set the status of a diff record to DiffStatus::Cancelled.
A cancelled record’s consume will subsequently return None (the
Validation error path in object_set_storage_class).
Returns AppError::NotFound when the id does not exist.
Sourcepub fn consume(&self, id: &DiffId) -> Option<DiffPayload>
pub fn consume(&self, id: &DiffId) -> Option<DiffPayload>
Consume a diff record on confirmation.
Returns Some(payload) exactly once for a record in Pending state
that has not yet expired. Sets the status to Confirmed.
Returns None when:
- The record does not exist.
- The record was cancelled.
- The record is expired (checked against wall clock).
- The record was already consumed (double-confirm rejection).
Sourcepub fn consume_at(&self, id: &DiffId, now: i64) -> Option<DiffPayload>
pub fn consume_at(&self, id: &DiffId, now: i64) -> Option<DiffPayload>
Consume at an explicit timestamp (test helper).
Sourcepub fn get(&self, id: &DiffId) -> Option<DiffRecord>
pub fn get(&self, id: &DiffId) -> Option<DiffRecord>
Read a diff record without consuming it.
Returns None when the id does not exist. Does not expire the record.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for DiffStore
impl RefUnwindSafe for DiffStore
impl Send for DiffStore
impl Sync for DiffStore
impl Unpin for DiffStore
impl UnsafeUnpin for DiffStore
impl UnwindSafe for DiffStore
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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