Closed yihuang closed 4 years ago
This is intended. The implementations (like rocksdb) need to hold a reference to the prefix. The user is expected to store the prefix somewhere that outlives the iterator. You can create an API that returns something like
struct Iter<'a> {
encoded_prefix: Vec<u8>,
db: &Db,
}
impl<'a> Iter<'a> {
fn iter(&self) -> impl Iterator<Item=...> {
self.db.iter_from_prefix(SOME_COL, &self.encoded_prefix)
}
}
We could clone the prefix somewhere in the internals of prefix iterator, but it's a question of convenience vs explicitness.
The implementations (like rocksdb) need to hold a reference to the prefix.
I might be wrong on this one, let me double check.
The
prefix
use the same lifetime marker asself
and return value, so the returned iterator can't live longer than prefix. I think this's not good, because prefix could be temporarily constructed. For example: