pub struct VersionChain<T> { /* private fields */ }Expand description
All versions of a single entity, newest first.
Each node/edge has one of these tracking its version history. Use
visible_at() to get the version at a specific epoch,
or visible_to() for transaction-aware visibility.
Implementations§
Source§impl<T> VersionChain<T>
impl<T> VersionChain<T>
Sourcepub fn new() -> VersionChain<T>
pub fn new() -> VersionChain<T>
Creates a new empty version chain.
Sourcepub fn with_initial(
data: T,
created_epoch: EpochId,
created_by: TxId,
) -> VersionChain<T>
pub fn with_initial( data: T, created_epoch: EpochId, created_by: TxId, ) -> VersionChain<T>
Creates a version chain with an initial version.
Sourcepub fn add_version(&mut self, data: T, created_epoch: EpochId, created_by: TxId)
pub fn add_version(&mut self, data: T, created_epoch: EpochId, created_by: TxId)
Adds a new version to the chain.
The new version becomes the head of the chain.
Sourcepub fn visible_at(&self, epoch: EpochId) -> Option<&T>
pub fn visible_at(&self, epoch: EpochId) -> Option<&T>
Finds the version visible at the given epoch.
Returns a reference to the visible version’s data, or None if no version
is visible at that epoch.
Sourcepub fn visible_to(&self, epoch: EpochId, tx: TxId) -> Option<&T>
pub fn visible_to(&self, epoch: EpochId, tx: TxId) -> Option<&T>
Finds the version visible to a specific transaction.
This considers both the transaction’s epoch and its own uncommitted changes.
Sourcepub fn mark_deleted(&mut self, delete_epoch: EpochId) -> bool
pub fn mark_deleted(&mut self, delete_epoch: EpochId) -> bool
Marks the current visible version as deleted.
Returns true if a version was marked, false if no visible version exists.
Sourcepub fn modified_by(&self, tx: TxId) -> bool
pub fn modified_by(&self, tx: TxId) -> bool
Checks if any version was modified by the given transaction.
Sourcepub fn remove_versions_by(&mut self, tx: TxId)
pub fn remove_versions_by(&mut self, tx: TxId)
Removes all versions created by the given transaction.
Used for rollback to discard uncommitted changes.
Sourcepub fn has_conflict(&self, start_epoch: EpochId, our_tx: TxId) -> bool
pub fn has_conflict(&self, start_epoch: EpochId, our_tx: TxId) -> bool
Checks if there’s a concurrent modification conflict.
A conflict exists if another transaction modified this entity after our start epoch.
Sourcepub fn version_count(&self) -> usize
pub fn version_count(&self) -> usize
Returns the number of versions in the chain.
Sourcepub fn gc(&mut self, min_epoch: EpochId)
pub fn gc(&mut self, min_epoch: EpochId)
Garbage collects old versions that are no longer visible to any transaction.
Keeps versions that might still be visible to transactions at or after min_epoch.
Sourcepub fn latest(&self) -> Option<&T>
pub fn latest(&self) -> Option<&T>
Returns a reference to the latest version’s data regardless of visibility.
Sourcepub fn latest_mut(&mut self) -> Option<&mut T>
pub fn latest_mut(&mut self) -> Option<&mut T>
Returns a mutable reference to the latest version’s data.
Source§impl<T> VersionChain<T>where
T: Clone,
impl<T> VersionChain<T>where
T: Clone,
Trait Implementations§
Source§impl<T> Clone for VersionChain<T>where
T: Clone,
impl<T> Clone for VersionChain<T>where
T: Clone,
Source§fn clone(&self) -> VersionChain<T>
fn clone(&self) -> VersionChain<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> Debug for VersionChain<T>where
T: Debug,
impl<T> Debug for VersionChain<T>where
T: Debug,
Source§impl<T> Default for VersionChain<T>
impl<T> Default for VersionChain<T>
Source§fn default() -> VersionChain<T>
fn default() -> VersionChain<T>
Auto Trait Implementations§
impl<T> Freeze for VersionChain<T>
impl<T> RefUnwindSafe for VersionChain<T>where
T: RefUnwindSafe,
impl<T> Send for VersionChain<T>where
T: Send,
impl<T> Sync for VersionChain<T>where
T: Sync,
impl<T> Unpin for VersionChain<T>where
T: Unpin,
impl<T> UnwindSafe for VersionChain<T>where
T: UnwindSafe,
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