Iterator over a temporary variable

#1

I am trying to construct an iterator over an object that is backed by an LMDB database. Iterating over the key-value pairs normally looks like the following:

let transaction = env.begin_ro_txn()?;
let cursor = transaction.open_ro_cursor(&db)?;
for (key, value) in cursor.iter_start() {
    ...
}

Now, I have a struct

pub struct LMDBSink {
    env: lmdb::Environment,
    db: lmdb::Database,
}

over which I would like to iterate directly. To this end, I have created an iterator struct containing the variables used in the example above:

pub struct LMDBSinkIter<'sink> {
    txn: lmdb::RoTransaction<'sink>,
    cursor: lmdb::RoCursor<'sink>,
    iter: lmdb::Iter<'sink>,
}

But I’m not able to construct this object, because the txn field before being moved into the struct is local to the function creating the iterator, and I have to borrow from it to create the cursor.

Here is my first attempt, though note that the library/database part has a layer of indirection removed.

Does anyone have any suggestions for how I might build this iterator using only safe rust?