Skip to main content

Transaction

Struct Transaction 

pub struct Transaction<'a, T, L, J>
where T: LinkReference, L: Doublets<T>, J: TransitionLog<T>,
{ /* private fields */ }
Expand description

An exclusively borrowed transaction; unfinished handles roll back on drop.

commit and rollback consume the handle. If commit returns an I/O error, its outcome is indeterminate until journal recovery: an append may have reached disk despite reporting failure. Further writes are blocked on that decorator. Call explicit rollback to receive restoration errors; drop records them in TransactionsDecorator::rollback_error and never panics intentionally.

Implementations§

§

impl<T, L, J> Transaction<'_, T, L, J>
where T: LinkReference, L: Doublets<T>, J: TransitionLog<T>,

pub fn commit(self) -> Result<(), Error<T>>

Commits the transaction after persisting the complete resulting graph.

pub fn rollback(self) -> Result<(), Error<T>>

Restores the original graph and records the rollback.

pub fn transitions(&self) -> &[Transition<T>]

Transitions recorded by this transaction so far.

Methods from Deref<Target = TransactionsDecorator<T, L, J>>§

pub fn begin_transaction( &mut self, ) -> Result<Transaction<'_, T, L, J>, Error<T>>

Starts a transaction, persisting its before snapshot first.

Nested transactions are rejected. The handle exclusively borrows this decorator; dropping it without completion rolls back, including on unwind.

pub fn inner(&self) -> &L

Returns the wrapped store for read-only inspection.

pub fn journal(&self) -> &J

Returns the journal for read-only inspection.

pub fn transitions(&self) -> &[Transition<T>]

All recorded transitions, including writes subsequently rolled back.

pub fn is_poisoned(&self) -> bool

Whether an I/O or restoration failure has blocked further writes.

pub fn set_tracing(&mut self, enabled: bool)

Enables diagnostic transaction and transition messages on stderr. Disabled by default.

pub fn rollback_error(&self) -> Option<&str>

The last rollback failure, including one encountered by a handle’s drop.

Drop cannot return an error. A failed rollback poisons the decorator and leaves the begin record available for recovery when the store is reopened.

Trait Implementations§

§

impl<T, L, J> Deref for Transaction<'_, T, L, J>
where T: LinkReference, L: Doublets<T>, J: TransitionLog<T>,

§

type Target = TransactionsDecorator<T, L, J>

The resulting type after dereferencing.
§

fn deref(&self) -> &<Transaction<'_, T, L, J> as Deref>::Target

Dereferences the value.
§

impl<T, L, J> DerefMut for Transaction<'_, T, L, J>
where T: LinkReference, L: Doublets<T>, J: TransitionLog<T>,

§

fn deref_mut(&mut self) -> &mut <Transaction<'_, T, L, J> as Deref>::Target

Mutably dereferences the value.
§

impl<T, L, J> Doublets<T> for Transaction<'_, T, L, J>
where T: LinkReference, L: Doublets<T>, J: TransitionLog<T>,

Returns the link at index, or None if it does not exist.
§

fn count_by(&self, query: impl ToQuery<T>) -> T
where Self: Sized,

Counts links matching query.
§

fn count(&self) -> T
where Self: Sized,

Returns the total number of links in the store.
§

fn create_by_with<F>( &mut self, query: impl ToQuery<T>, handler: F, ) -> Result<Flow, Error<T>>
where F: FnMut(Link<T>, Link<T>) -> Flow, Self: Sized,

Creates a link matching query, calling handler on each created link.
§

fn create_by(&mut self, query: impl ToQuery<T>) -> Result<T, Error<T>>
where Self: Sized,

Creates a link matching query and returns its index.
§

fn create_with<F>(&mut self, handler: F) -> Result<Flow, Error<T>>
where F: FnMut(Link<T>, Link<T>) -> Flow, Self: Sized,

Creates a new link and calls handler with the before/after states.
§

fn create(&mut self) -> Result<T, Error<T>>
where Self: Sized,

Creates a new uninitialized link and returns its index.
§

fn each_by<F>(&self, query: impl ToQuery<T>, handler: F) -> Flow
where F: FnMut(Link<T>) -> Flow, Self: Sized,

Iterates over links matching query, calling handler for each.
§

fn each<F>(&self, handler: F) -> Flow
where F: FnMut(Link<T>) -> Flow, Self: Sized,

Iterates over all links in the store, calling handler for each.
§

fn update_by_with<H>( &mut self, query: impl ToQuery<T>, change: impl ToQuery<T>, handler: H, ) -> Result<Flow, Error<T>>
where H: FnMut(Link<T>, Link<T>) -> Flow, Self: Sized,

Updates links matching query to change, calling handler with before/after.
§

fn update_by( &mut self, query: impl ToQuery<T>, change: impl ToQuery<T>, ) -> Result<T, Error<T>>
where Self: Sized,

Updates links matching query to change and returns the updated link’s index.
§

fn update_with<F>( &mut self, index: T, source: T, target: T, handler: F, ) -> Result<Flow, Error<T>>
where F: FnMut(Link<T>, Link<T>) -> Flow, Self: Sized,

Updates the link at index to (index, source, target), calling handler.
§

fn update(&mut self, index: T, source: T, target: T) -> Result<T, Error<T>>
where Self: Sized,

Updates the link at index to (index, source, target) and returns the index.
§

fn delete_by_with<F>( &mut self, query: impl ToQuery<T>, handler: F, ) -> Result<Flow, Error<T>>
where F: FnMut(Link<T>, Link<T>) -> Flow, Self: Sized,

Deletes links matching query, calling handler with before/after states.
§

fn delete_by(&mut self, query: impl ToQuery<T>) -> Result<T, Error<T>>
where Self: Sized,

Deletes links matching query and returns the deleted link’s index.
§

fn delete_with<F>(&mut self, index: T, handler: F) -> Result<Flow, Error<T>>
where F: FnMut(Link<T>, Link<T>) -> Flow, Self: Sized,

Deletes the link at index, calling handler with before/after states.
§

fn delete(&mut self, index: T) -> Result<T, Error<T>>
where Self: Sized,

Deletes the link at index and returns its former index.
Returns the link at index, or Err(Error::NotExists) if it does not exist.
§

fn delete_all(&mut self) -> Result<(), Error<T>>
where Self: Sized,

Deletes all links in reverse enumeration order. Links already removed by cascading deletions are skipped.
§

fn delete_query_with<F>( &mut self, query: impl ToQuery<T>, handler: F, ) -> Result<(), Error<T>>
where F: FnMut(Link<T>, Link<T>) -> Flow, Self: Sized,

Deletes all links matching query, calling handler for each deletion. Duplicate matches are deleted once, in reverse order of their first occurrence.
§

fn delete_usages_with<F>( &mut self, index: T, handler: F, ) -> Result<(), Error<T>>
where F: FnMut(Link<T>, Link<T>) -> Flow, Self: Sized,

Deletes each other link that uses index as a source or target once, calling handler for each deletion.
§

fn delete_usages(&mut self, index: T) -> Result<(), Error<T>>
where Self: Sized,

Deletes all links that use index as a source or target.
§

fn create_point(&mut self) -> Result<T, Error<T>>
where Self: Sized,

Creates a self-referential point link and returns its index.
Creates a link from source to target, calling handler with before/after states. Read more
Creates a link from source to target and returns its index.
§

fn found(&self, query: impl ToQuery<T>) -> bool
where Self: Sized,

Returns true if at least one link matches query.
§

fn find(&self, query: impl ToQuery<T>) -> Option<Link<T>>
where Self: Sized,

Returns the first link matching query, or None.
§

fn search(&self, source: T, target: T) -> Option<T>
where Self: Sized,

Returns the index of a link with the given source and target, or None.
§

fn search_or(&self, source: T, target: T, default: T) -> T
where Self: Sized,

👎Deprecated:

use search instead

§

fn single(&self, query: impl ToQuery<T>) -> Option<Link<T>>
where Self: Sized,

Returns the link matching query only if exactly one link matches; None otherwise.
§

fn get_or_create(&mut self, source: T, target: T) -> Result<T, Error<T>>
where Self: Sized,

Returns the index of the (source, target) link, creating it if it does not exist.
§

fn count_usages(&self, index: T) -> Result<T, Error<T>>
where Self: Sized,

Returns the number of distinct other links that reference index as a source or target.
§

fn usages(&self, index: T) -> Result<Vec<T>, Error<T>>
where Self: Sized,

Returns the indices of distinct other links that reference index as a source or target.
§

fn exist(&self, link: T) -> bool
where Self: Sized,

Returns true if the link at link exists (internal or external).
§

fn has_usages(&self, link: T) -> bool
where Self: Sized,

Returns true if any other link references link as a source or target.
§

fn rebase_with<F>(&mut self, old: T, new: T, handler: F) -> Result<(), Error<T>>
where F: FnMut(Link<T>, Link<T>) -> Flow, Self: Sized,

Re-points all usages of old to new, calling handler for each update. Read more
§

fn rebase(&mut self, old: T, new: T) -> Result<T, Error<T>>
where Self: Sized,

Re-points all usages of old to new and returns new.
§

fn rebase_and_delete(&mut self, old: T, new: T) -> Result<T, Error<T>>
where Self: Sized,

Re-points all usages of old to new, then deletes old. Returns new.
§

impl<T, L, J> Drop for Transaction<'_, T, L, J>
where T: LinkReference, L: Doublets<T>, J: TransitionLog<T>,

§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
§

impl<T, L, J> Links<T> for Transaction<'_, T, L, J>
where T: LinkReference, L: Doublets<T>, J: TransitionLog<T>,

§

fn constants(&self) -> &LinksConstants<T>

Returns the store’s [LinksConstants] (any/null/range values).
Counts links that match query.
Iterates over links matching query, calling handler for each.
Creates one or more links matching query and reports each creation via handler.
Updates links matching query to the new values in change, reporting via handler.
Deletes links matching query and reports each deletion via handler. Read more

Auto Trait Implementations§

§

impl<'a, T, L, J> !UnwindSafe for Transaction<'a, T, L, J>

§

impl<'a, T, L, J> Freeze for Transaction<'a, T, L, J>

§

impl<'a, T, L, J> RefUnwindSafe for Transaction<'a, T, L, J>

§

impl<'a, T, L, J> Send for Transaction<'a, T, L, J>

§

impl<'a, T, L, J> Sync for Transaction<'a, T, L, J>

§

impl<'a, T, L, J> Unpin for Transaction<'a, T, L, J>

§

impl<'a, T, L, J> UnsafeUnpin for Transaction<'a, T, L, J>

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
§

impl<T, L> DecoratorsExt<T> for L
where T: LinkReference, L: Doublets<T>,

§

fn with_transactions<J>( self, journal: J, ) -> Result<TransactionsDecorator<T, Self, J>, Error<T>>
where J: TransitionLog<T>,

Wraps the store in TransactionsDecorator and recovers its journal.
§

fn with_uniqueness<P>( self, _policy: P, ) -> <P as UniquenessPolicy>::Decorator<T, Self>

§

fn with_usages<P>(self, _policy: P) -> <P as UsagesPolicy>::Decorator<T, Self>
where P: UsagesPolicy,

§

fn with_usages_validation(self) -> UsagesValidator<T, Self>

Wraps in UsagesValidator.
§

fn with_cascade_usages_resolution(self) -> CascadeUsagesResolver<T, Self>

§

fn with_inner_reference_existence_validation( self, ) -> InnerReferenceExistenceValidator<T, Self>

§

fn with_non_existent_dependencies_creation( self, ) -> NonExistentDependenciesCreator<T, Self>

§

fn with_non_existent_deletion_resolution( self, ) -> NonExistentDeletionResolver<T, Self>

Wraps in NonExistentDeletionResolver, ignoring deletion of missing links.
§

fn with_itself_constant_resolution( self, ) -> ItselfConstantToSelfReferenceResolver<T, Self>

§

fn with_null_constant_resolution( self, ) -> NullConstantToSelfReferenceResolver<T, Self>

§

fn with_non_null_contents_deletion_resolution( self, ) -> NonNullContentsLinkDeletionResolver<T, Self>

§

fn with_logging<W>(self, writer: W) -> LoggingDecorator<T, Self, W>
where W: Write + Send + Sync,

Wraps in LoggingDecorator, logging every mutation to writer.
§

fn with_no_exceptions(self) -> NoExceptionsDecorator<T, Self>

§

fn with_automatic_uniqueness_and_usages_resolution( self, ) -> CascadeUniquenessAndUsagesResolver<T, NonNullContentsLinkDeletionResolver<T, CascadeUsagesResolver<T, Self>>>

Builds the same stack as C# ILinksExtensions.DecorateWithAutomaticUniquenessAndUsagesResolution: CascadeUsagesResolver innermost, then NonNullContentsLinkDeletionResolver, then CascadeUniquenessAndUsagesResolver outermost. The cascade explicitly resets each nested usage before descending, so handlers observe resets before the corresponding deletions, as with C#’s facade recursion. Read more
§

impl<T, All> DoubletsExt<T> for All
where T: LinkReference, All: Doublets<T>,

§

fn iter( &self, ) -> impl Iterator<Item = Link<T>> + ExactSizeIterator + DoubleEndedIterator

Returns an iterator over all links in the store.
§

fn each_iter( &self, query: impl ToQuery<T>, ) -> impl Iterator<Item = Link<T>> + ExactSizeIterator + DoubleEndedIterator

Returns an iterator over links matching query.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.