[][src]Struct ejdb::Transaction

pub struct Transaction<'coll, 'db: 'coll> { /* fields omitted */ }

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.

Methods

impl<'coll, 'db> Transaction<'coll, 'db>[src]

pub fn will_commit(&self) -> bool[src]

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.

pub fn will_abort(&self) -> bool[src]

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.

pub fn set_commit(&mut self)[src]

Makes this transaction commit when dropped.

pub fn set_abort(&mut self)[src]

Makes this transaction abort when dropped.

pub fn finish(self) -> Result<()>[src]

Aborts or commits the transaction depending on the finish mode.

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

pub fn commit(self) -> Result<()>[src]

Attempts to commit this transaction.

pub fn abort(self) -> Result<()>[src]

Attempts to abort this transaction.

Trait Implementations

impl<'coll, 'db> Drop for Transaction<'coll, 'db>[src]

Auto Trait Implementations

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

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

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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