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 outlived by its parent transaction (not
necessarily strictly). 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]
fn get<K: AsLmdbBytes + ?Sized, V: FromLmdbBytes + ?Sized>(&self,
db: &Database,
key: &K)
-> Result<&V>
db: &Database,
key: &K)
-> Result<&V>
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
.