pub struct WritebackJournal { /* private fields */ }Expand description
In-memory, per-session writeback journal.
Writes go into Self::entries; a future flush_to_disk(path)
helper will stream them to <session-id>.journal.jsonl. Keeping
disk I/O out of this type makes every phase fast to unit-test.
Implementations§
Source§impl WritebackJournal
impl WritebackJournal
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
The session this journal belongs to.
Sourcepub fn entries(&self) -> &[JournalEntry]
pub fn entries(&self) -> &[JournalEntry]
Every entry in the order it was appended.
Sourcepub fn stage(&mut self, op: Op) -> TxnId
pub fn stage(&mut self, op: Op) -> TxnId
Stage an op and return its TxnId. Writes a Staged entry.
§Examples
use codetether_agent::session::journal::{Op, WritebackJournal};
let mut journal = WritebackJournal::new("s");
let txn = journal.stage(Op::Save);
assert_eq!(journal.entries().len(), 1);
journal.commit(txn).unwrap();
assert_eq!(journal.entries().len(), 2);Sourcepub fn reject(&mut self, txn: TxnId, reason: RejectReason)
pub fn reject(&mut self, txn: TxnId, reason: RejectReason)
Mark a staged transaction as rejected with reason. The
transaction is dropped from the pending set — a subsequent
Self::commit on the same id returns Err(RejectReason).
Sourcepub fn commit(&mut self, txn: TxnId) -> Result<(), RejectReason>
pub fn commit(&mut self, txn: TxnId) -> Result<(), RejectReason>
Commit a staged transaction that passed validation. Returns
Err(RejectReason::SchemaMismatch) when the transaction is
unknown (never staged, or already rejected / committed).
§Errors
See above — returns Err when the TxnId is not pending.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Number of currently staged (neither committed nor rejected) transactions.
Trait Implementations§
Source§impl Clone for WritebackJournal
impl Clone for WritebackJournal
Source§fn clone(&self) -> WritebackJournal
fn clone(&self) -> WritebackJournal
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for WritebackJournal
impl RefUnwindSafe for WritebackJournal
impl Send for WritebackJournal
impl Sync for WritebackJournal
impl Unpin for WritebackJournal
impl UnsafeUnpin for WritebackJournal
impl UnwindSafe for WritebackJournal
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request