Skip to main content

Transaction

Struct Transaction 

Source
pub struct Transaction<'a> { /* private fields */ }
Expand description

Representation of a transaction in STM.

Implementations§

Source§

impl<'a> Transaction<'a>

Source

pub fn on_commit<F>(&mut self, f: F)
where F: FnOnce() + Send + 'static,

Schedule a side-effect (I/O) to run ONLY if the transaction commits successfully.

This closure will run after all locks are released.

Source

pub fn on_rollback<F>(&mut self, f: F)
where F: FnOnce() + Send + 'static,

Schedule a side-effect to run ONLY if the transaction aborts or fails.

This is useful for cleaning up temporary resources or logging failures. It runs when the transaction is dropped without committing.

§Example
let tmp_file = create_temp_file();
tx.on_rollback(move || remove_file(tmp_file));
Source

pub fn load<T: Any + Send + Sync + Clone>( &mut self, tvar: &TVar<T>, ) -> Result<T, StmError>

Read a TVar.

The TVar wrapper contains an Arc<TVarInner<T>>. This method clones the Arc into the read entry (_keep_alive), so the version_lock pointer stored in ReadEntry.lock_atomic remains valid even if the TVar handle is dropped before commit() runs. The stable identity key is Arc::as_ptr(&tvar.0) - the address of the heap-allocated TVarInner, which is invariant across TVar clones.

Source

pub fn store<T: Any + Send + Sync + 'static>( &mut self, tvar: &TVar<T>, val: T, ) -> Result<(), StmError>

Write to a TVar.

This method clones the Arc<TVarInner<T>> from the TVar wrapper and moves it into the committer closure. The committer is invoked during commit(), which may run after the TVar handle is dropped. The Arc clone ensures the TVarInner (and thus version_lock and data) remains alive until the commit closure executes.

Trait Implementations§

Source§

impl<'a> Drop for Transaction<'a>

Source§

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

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Transaction<'a>

§

impl<'a> !Send for Transaction<'a>

§

impl<'a> !Sync for Transaction<'a>

§

impl<'a> !UnwindSafe for Transaction<'a>

§

impl<'a> Forget for Transaction<'a>

§

impl<'a> Freeze for Transaction<'a>

§

impl<'a> Move for Transaction<'a>

§

impl<'a> Unpin for Transaction<'a>

§

impl<'a> UnsafeUnpin for Transaction<'a>

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> 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<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.