Skip to main content

VersionChain

Struct VersionChain 

Source
pub struct VersionChain<T> { /* private fields */ }
Expand description

A chain of versions for a single entity.

Versions are stored newest-first for efficient access to recent versions. Old versions can be garbage collected when no active transactions can see them.

Implementations§

Source§

impl<T> VersionChain<T>

Source

pub fn new() -> VersionChain<T>

Creates a new empty version chain.

Source

pub fn with_initial( data: T, created_epoch: EpochId, created_by: TxId, ) -> VersionChain<T>

Creates a version chain with an initial version.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn modified_by(&self, tx: TxId) -> bool

Checks if any version was modified by the given transaction.

Source

pub fn remove_versions_by(&mut self, tx: TxId)

Removes all versions created by the given transaction.

Used for rollback to discard uncommitted changes.

Source

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.

Source

pub fn version_count(&self) -> usize

Returns the number of versions in the chain.

Source

pub fn is_empty(&self) -> bool

Returns true if the chain has no versions.

Source

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.

Source

pub fn latest(&self) -> Option<&T>

Returns a reference to the latest version’s data regardless of visibility.

Source

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,

Source

pub fn get_mut( &mut self, epoch: EpochId, tx: TxId, modify_epoch: EpochId, ) -> Option<&mut T>

Gets a mutable reference to the visible version’s data for modification.

If the version is not owned by this transaction, creates a new version with a copy of the data.

Trait Implementations§

Source§

impl<T> Clone for VersionChain<T>
where T: Clone,

Source§

fn clone(&self) -> VersionChain<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for VersionChain<T>
where T: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> Default for VersionChain<T>

Source§

fn default() -> VersionChain<T>

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more