Struct Transaction

Source
pub struct Transaction<'coll, 'db: 'coll> { /* private fields */ }
Expand description

Represents an active transaction.

This structure is a transaction guard for an EJDB collection. It employs the RAII pattern: a value of this structure is returned when a transaction is started and when this value is dropped, the transaction is committed or aborted.

By default when a transaction goes out of scope, it is aborted. This is done because of the way how errors are handled in Rust: if you interleave working with an EJDB collection with other, potentially failing operations, then it is possible for an error to cause an early return, dropping the transaction in progress. In this case aborting the transaction is usually the most natural option.

However, it is possible to change the default behavior with set_commit()/set_abort() methods, and it is also possible to commit or abort the transaction with commit()/abort() methods. finish() method is essentially equivalent to dropping the transaction guard, except that it returns a value which may contain an error (for regular drops any errors are ignored). will_commit()/will_abort() methods return true if their respective action will be taken upon finishing.

In EJDB transactions can only span one collection, therefore transactions created from a collection has a direct lifetime dependency on it.

See Collection::begin_transaction() documentation for examples.

Implementations§

Source§

impl<'coll, 'db> Transaction<'coll, 'db>

Source

pub fn will_commit(&self) -> bool

Checks whether this transaction will be committed upon drop.

Returns true if this transaction will be committed when dropped or when finish() method is called.

Source

pub fn will_abort(&self) -> bool

Checks whether this transaction will be aborted upon drop.

Returns true if this transaction will be aborted when dropped or when finish() method is called.

Source

pub fn set_commit(&mut self)

Makes this transaction commit when dropped.

Source

pub fn set_abort(&mut self)

Makes this transaction abort when dropped.

Source

pub fn finish(self) -> Result<()>

Aborts or commits the transaction depending on the finish mode.

The mode can be changed with set_commit() and set_abort() methods.

Source

pub fn commit(self) -> Result<()>

Attempts to commit this transaction.

Source

pub fn abort(self) -> Result<()>

Attempts to abort this transaction.

Trait Implementations§

Source§

impl<'coll, 'db> Drop for Transaction<'coll, 'db>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'coll, 'db> Freeze for Transaction<'coll, 'db>

§

impl<'coll, 'db> RefUnwindSafe for Transaction<'coll, 'db>

§

impl<'coll, 'db> !Send for Transaction<'coll, 'db>

§

impl<'coll, 'db> !Sync for Transaction<'coll, 'db>

§

impl<'coll, 'db> Unpin for Transaction<'coll, 'db>

§

impl<'coll, 'db> UnwindSafe for Transaction<'coll, 'db>

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 = 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, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

Source§

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