Struct lmdb_zero::ConstAccessor [] [src]

pub struct ConstAccessor<'txn>(_);

A read-only data accessor obtained from a ConstTransaction.

There is no corresponding ReadAccessor, since there are no additional operations one can do with a known-read-only accessor.

Lifetime

A ConstAccessor must be strictly outlived by its parent transaction. The parent transaction cannot be destroyed (committed, etc) until the borrow from the accessor ends. This in many cases requires adding an extra scope (with bare { } braces) in which to obtain the accessor, as can be seen in many of the examples.

The lifitem of a reference to a ConstAccessor dictates the lifetime of the data accessed via the accessor.

The 'txn lifetime parameter is covariant. That is, given two lifetimes 'x and 'y where 'x: 'y, a &ConstAccessor<'x> can be implicitly coerced into a &ConstAccessor<'y>.

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

Because of this property, if you need to hold onto an &lmdb::ConstAccessor 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::ConstAccessor<'x>.

Methods

impl<'txn> ConstAccessor<'txn>
[src]

[src]

Get items from a database.

This function retrieves key/data pairs from the database. A reference to the data associated with the given key is returned. If the database supports duplicate keys (DUPSORT) then the first data item for the key will be returned. Retrieval of other items requires the use of cursoring.

The returned memory is valid until the next mutation through the transaction or the end of the transaction (both are enforced through the borrow checker).

Errors

This call may return errors for reasons other than the key not being found. The easiest way to handle "not found" is generally to use the to_opt method on traits::LmdbResultExt to promote the value into a Result<Option<V>>. Most important of these other errors is the possibility of the key being found, but the value not being convertible to a &V.

Trait Implementations

impl<'txn> Debug for ConstAccessor<'txn>
[src]

[src]

Formats the value using the given formatter. Read more

impl<'txn> Drop for ConstAccessor<'txn>
[src]

ConstAccessor implements Drop trait so that if it gets dropped, a new accessor can be safely obtained

[src]

Executes the destructor for this type. Read more

Auto Trait Implementations

impl<'txn> !Send for ConstAccessor<'txn>

impl<'txn> !Sync for ConstAccessor<'txn>