Struct lmdb_zero::ConstTransaction [] [src]

pub struct ConstTransaction<'env> { /* fields omitted */ }

Base functionality for an LMDB transaction.

The type is "const" in a similar usage to the modifier in C: One cannot use it to make any modifications, but also cannot rely on it actually being read-only. ConstTransactions are used to write code that can operate in either kind of transaction.

Unlike most other LMDB wrappers, transactions here are (indirectly) the things in control of accessing data behind cursors. This is in order to correctly express memory semantics: Moving a cursor does not invalidate memory obtained from the cursor; however, any mutation through the same transaction does. We therefore model accesses to data in the environment as borrows of the transaction and the database themselves (possibly mutable on the latter), which allows the borrow checker to ensure that all references are dropped before doing a structural modification.

Note that due to limitations in the Rust borrow checker, one actually needs to use the *Accessor structs to access data. Any transaction will yield at most one accessor, which is implemented with a runtime check that should in the vast majority of cases get optimised out.

Mutability of a transaction reference does not indicate mutability of the underlying database, but rather exclusivity for enforcement of child transaction semantics.

Lifetime

A ConstTransaction must be strictly outlived by its Environment.

'env is covariant: given two lifetimes 'x and 'y where 'x: 'y, a &ConstTransaction<'x> will implicitly coerce to &ConstTransaction<'y>.

fn convariance<'x, 'y>(db: &lmdb::ConstTransaction<'x>)
where 'x: 'y {
  let _db2: &lmdb::ConstTransaction<'y> = db;
}

Because of this property, if you need to hold onto an &lmdb::ConstTransaction and must explicitly name both lifetimes, it is usually best to use the same lifetime for both the reference and the parameter, eg &'x lmdb::ConstTransaction<'x>.

Methods

impl<'env> ConstTransaction<'env>
[src]

Returns an accessor used to manipulate data in this transaction.

Panics

Panics if this function has already been called on this transaction.

Example

let txn = lmdb::ReadTransaction::new(&env).unwrap();
// Get access the first time
let access = txn.access();

// You can't get the accessor again, since this would create two
// references to the same logical memory and allow creating aliased
// mutable references and so forth.
let access2 = txn.access(); // PANIC!

Creates a new cursor scoped to this transaction, bound to the given database.

Returns the internal id of this transaction.

Retrieves statistics for a database.

Retrieve the DB flags for a database handle.

Trait Implementations

impl<'env> Debug for ConstTransaction<'env>
[src]

Formats the value using the given formatter.