Struct ord_lmdb_zero::ConstAccessor
source · [−]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
sourceimpl<'txn> ConstAccessor<'txn>
impl<'txn> ConstAccessor<'txn>
sourcepub fn get<K: AsLmdbBytes + ?Sized, V: FromLmdbBytes + ?Sized>(
&self,
db: &Database<'_>,
key: &K
) -> Result<&V>
pub fn get<K: AsLmdbBytes + ?Sized, V: FromLmdbBytes + ?Sized>(
&self,
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
.
Trait Implementations
sourceimpl<'txn> Debug for ConstAccessor<'txn>
impl<'txn> Debug for ConstAccessor<'txn>
Auto Trait Implementations
impl<'txn> !RefUnwindSafe for ConstAccessor<'txn>
impl<'txn> !Send for ConstAccessor<'txn>
impl<'txn> !Sync for ConstAccessor<'txn>
impl<'txn> Unpin for ConstAccessor<'txn>
impl<'txn> !UnwindSafe for ConstAccessor<'txn>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> SafeBorrow<T> for T where
T: ?Sized,
impl<T> SafeBorrow<T> for T where
T: ?Sized,
sourcefn borrow_replacement(ptr: &T) -> &T
fn borrow_replacement(ptr: &T) -> &T
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