pub struct ChangeLog { /* private fields */ }Expand description
A thread-safe, cloneable transaction log for collecting database operations.
This struct acts as a “Unit of Work,” allowing multiple threads to concurrently
record operations without directly mutating the Database. The collected changes
can then be applied later in a single batch operation. This pattern avoids lock
contention on the main database during processing.
Implementations§
Source§impl ChangeLog
impl ChangeLog
Sourcepub fn add(&self, file: File) -> Result<(), DatabaseError>
pub fn add(&self, file: File) -> Result<(), DatabaseError>
Records a request to add a new file.
§Errors
Returns a DatabaseError::PoisonedLogMutex if another thread panicked
while holding the lock, leaving the change log in an unusable state.
Sourcepub fn update(
&self,
id: FileId,
new_contents: Cow<'static, str>,
) -> Result<(), DatabaseError>
pub fn update( &self, id: FileId, new_contents: Cow<'static, str>, ) -> Result<(), DatabaseError>
Records a request to update an existing file’s content by its FileId.
§Errors
Returns a DatabaseError::PoisonedLogMutex if another thread panicked
while holding the lock, leaving the change log in an unusable state.
Sourcepub fn delete(&self, id: FileId) -> Result<(), DatabaseError>
pub fn delete(&self, id: FileId) -> Result<(), DatabaseError>
Records a request to delete a file by its FileId.
§Errors
Returns a DatabaseError::PoisonedLogMutex if another thread panicked
while holding the lock, leaving the change log in an unusable state.
Sourcepub fn into_inner(self) -> Result<Vec<Change>, DatabaseError>
pub fn into_inner(self) -> Result<Vec<Change>, DatabaseError>
Consumes the change log and returns the vector of collected changes.
This operation safely unwraps the underlying list of changes. It will only succeed if called on the last remaining reference to the change log, which guarantees that no other threads can be modifying the list.
§Errors
DatabaseError::ChangeLogInUse: Returned if otherArcreferences to this change log still exist.DatabaseError::PoisonedLogMutex: Returned if the internal lock was poisoned because another thread panicked while holding it.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ChangeLog
impl RefUnwindSafe for ChangeLog
impl Send for ChangeLog
impl Sync for ChangeLog
impl Unpin for ChangeLog
impl UnwindSafe for ChangeLog
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