pub struct Transaction { /* private fields */ }Expand description
Transaction for atomic file operations.
The Transaction manages file snapshots and provides rollback capability. Files are snapshot before mutation, and can be restored to their original state if the transaction fails.
Implementations§
Source§impl Transaction
impl Transaction
Sourcepub async fn begin() -> Result<Self, AgentError>
pub async fn begin() -> Result<Self, AgentError>
Begins a new transaction with a unique ID.
Creates a fresh transaction with no snapshots and Active state.
Sourcepub async fn snapshot_file(&mut self, path: &Path) -> Result<(), AgentError>
pub async fn snapshot_file(&mut self, path: &Path) -> Result<(), AgentError>
Snapshots a file before mutation.
If the file exists, stores its content for rollback. If the file doesn’t exist, stores an empty snapshot (indicating the file should be deleted on rollback).
§Arguments
path- Path to the file to snapshot
Sourcepub async fn rollback(self) -> Result<(), AgentError>
pub async fn rollback(self) -> Result<(), AgentError>
Rolls back the transaction, restoring all files to original state.
Iterates through snapshots in reverse order and restores each file. Files that didn’t exist before are deleted.
§Errors
Returns an error if the transaction is not in Active state.
Sourcepub async fn commit(self) -> Result<Uuid, AgentError>
pub async fn commit(self) -> Result<Uuid, AgentError>
Sourcepub fn state(&self) -> &TransactionState
pub fn state(&self) -> &TransactionState
Returns the current transaction state.
Trait Implementations§
Source§impl Clone for Transaction
impl Clone for Transaction
Source§fn clone(&self) -> Transaction
fn clone(&self) -> Transaction
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 Transaction
impl RefUnwindSafe for Transaction
impl Send for Transaction
impl Sync for Transaction
impl Unpin for Transaction
impl UnsafeUnpin for Transaction
impl UnwindSafe for Transaction
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 more