Struct exonum_rocksdb::DBRawIterator
[−]
[src]
pub struct DBRawIterator { /* fields omitted */ }
An iterator over a database or column family, with specifiable ranges and direction.
This iterator is different to the standard DBIterator
as it aims Into
replicate the underlying iterator API within RocksDB itself. This should
give access to more performance and flexibility but departs from the
widely recognised Rust idioms.
extern crate tempdir; extern crate exonum_rocksdb; use exonum_rocksdb::DB; use tempdir::TempDir; let temp_dir = TempDir::new("storage4").unwrap(); let mut db = DB::open_default(temp_dir.path()).unwrap(); let mut iter = db.raw_iterator(); // Forwards iteration iter.seek_to_first(); while iter.valid() { println!("Saw {:?} {:?}", iter.key(), iter.value()); iter.next(); } // Reverse iteration iter.seek_to_last(); while iter.valid() { println!("Saw {:?} {:?}", iter.key(), iter.value()); iter.prev(); } // Seeking iter.seek(b"my key"); while iter.valid() { println!("Saw {:?} {:?}", iter.key(), iter.value()); iter.next(); }
Methods
impl DBRawIterator
[src]
fn new_txn(txn: &Transaction, readopts: &ReadOptions) -> DBRawIterator
[src]
fn valid(&self) -> bool
[src]
Returns true if the iterator is valid.
fn seek_to_first(&mut self)
[src]
Seeks to the first key in the database.
Examples
extern crate exonum_rocksdb; extern crate tempdir; use exonum_rocksdb::DB; use tempdir::TempDir; let temp_dir = TempDir::new("storage5").unwrap(); let mut db = DB::open_default(temp_dir.path()).unwrap(); let mut iter = db.raw_iterator(); // Iterate all keys from the start in lexicographic order iter.seek_to_first(); while iter.valid() { println!("{:?} {:?}", iter.key(), iter.value()); iter.next(); } // Read just the first key iter.seek_to_first(); if iter.valid() { println!("{:?} {:?}", iter.key(), iter.value()); } else { // There are no keys in the database }
fn seek_to_last(&mut self)
[src]
Seeks to the last key in the database.
Examples
extern crate exonum_rocksdb; extern crate tempdir; use exonum_rocksdb::DB; use tempdir::TempDir; let temp_dir = TempDir::new("storage6").unwrap(); let mut db = DB::open_default(temp_dir.path()).unwrap(); let mut iter = db.raw_iterator(); // Iterate all keys from the end in reverse lexicographic order iter.seek_to_last(); while iter.valid() { println!("{:?} {:?}", iter.key(), iter.value()); iter.prev(); } // Read just the last key iter.seek_to_last(); if iter.valid() { println!("{:?} {:?}", iter.key(), iter.value()); } else { // There are no keys in the database }
fn seek(&mut self, key: &[u8])
[src]
Seeks to the specified key or the first key that lexicographically follows it.
This method will attempt to seek to the specified key. If that key does not exist, it will find and seek to the key that lexicographically follows it instead.
Examples
extern crate exonum_rocksdb; extern crate tempdir; use exonum_rocksdb::DB; use tempdir::TempDir; let temp_dir = TempDir::new("storage7").unwrap(); let mut db = DB::open_default(temp_dir.path()).unwrap(); let mut iter = db.raw_iterator(); // Read the first key that starts with 'a' iter.seek(b"a"); if iter.valid() { println!("{:?} {:?}", iter.key(), iter.value()); } else { // There are no keys in the database }
fn next(&mut self)
[src]
Seeks to the next key.
Returns true if the iterator is valid after this operation.
fn prev(&mut self)
[src]
Seeks to the previous key.
Returns true if the iterator is valid after this operation.
unsafe fn key_inner<'a>(&'a self) -> Option<&'a [u8]>
[src]
Returns a slice to the internal buffer storing the current key.
This may be slightly more performant to use than the standard .key()
method
as it does not copy the key. However, you must be careful to not use the buffer
if the iterator's seek position is ever moved by any of the seek commands or the
.next()
and .previous()
methods as the underlying buffer may be reused
for something else or freed entirely.
fn key(&self) -> Option<Vec<u8>>
[src]
Returns a copy of the current key.
unsafe fn value_inner<'a>(&'a self) -> Option<&'a [u8]>
[src]
Returns a slice to the internal buffer storing the current value.
This may be slightly more performant to use than the standard .value()
method
as it does not copy the value. However, you must be careful to not use the buffer
if the iterator's seek position is ever moved by any of the seek commands or the
.next()
and .previous()
methods as the underlying buffer may be reused
for something else or freed entirely.
fn value(&self) -> Option<Vec<u8>>
[src]
Returns a copy of the current value.