pub struct ConstAccessor<'txn>(_);
Expand description

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

Implementations

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

Formats the value using the given formatter. Read more

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

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Given ptr, which was obtained from a prior call to Self::borrow(), return a value with the same nominal lifetime which is guaranteed to survive mutations to Self. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.