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. ConstTransaction
s 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]
fn access(&self) -> ConstAccessor
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!
fn cursor<'txn, 'db>(&'txn self, db: &'db Database) -> Result<Cursor<'txn, 'db>>
Creates a new cursor scoped to this transaction, bound to the given database.
fn id(&self) -> usize
Returns the internal id of this transaction.
fn db_stat(&self, db: &Database) -> Result<Stat>
Retrieves statistics for a database.
fn db_flags(&self, db: &Database) -> Result<Flags>
Retrieve the DB flags for a database handle.