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: String,
) -> Result<(), DatabaseError>
pub fn update( &self, id: FileId, new_contents: String, ) -> 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.