rocksdb

Type Alias DBRawIterator

Source
pub type DBRawIterator<'a> = DBRawIteratorWithThreadMode<'a, DB>;
Expand description

A type alias to keep compatibility. See DBRawIteratorWithThreadMode for details

Aliased Type§

struct DBRawIterator<'a> { /* private fields */ }

Implementations

Source§

impl<'a, D: DBAccess> DBRawIteratorWithThreadMode<'a, D>

Source

pub fn valid(&self) -> bool

Returns true if the iterator is valid. An iterator is invalidated when it reaches the end of its defined range, or when it encounters an error.

To check whether the iterator encountered an error after valid has returned false, use the status method. status will never return an error when valid is true.

Source

pub fn status(&self) -> Result<(), Error>

Returns an error Result if the iterator has encountered an error during operation. When an error is encountered, the iterator is invalidated and valid will return false when called.

Performing a seek will discard the current status.

Source

pub fn seek_to_first(&mut self)

Seeks to the first key in the database.

§Examples
use rocksdb::{DB, Options};

let path = "_path_for_rocksdb_storage5";
{
    let db = DB::open_default(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
    }
}
let _ = DB::destroy(&Options::default(), path);
Source

pub fn seek_to_last(&mut self)

Seeks to the last key in the database.

§Examples
use rocksdb::{DB, Options};

let path = "_path_for_rocksdb_storage6";
{
    let db = DB::open_default(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
    }
}
let _ = DB::destroy(&Options::default(), path);
Source

pub fn seek<K: AsRef<[u8]>>(&mut self, key: K)

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
use rocksdb::{DB, Options};

let path = "_path_for_rocksdb_storage7";
{
    let db = DB::open_default(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
    }
}
let _ = DB::destroy(&Options::default(), path);
Source

pub fn seek_for_prev<K: AsRef<[u8]>>(&mut self, key: K)

Seeks to the specified key, or the first key that lexicographically precedes it.

Like .seek() this method will attempt to seek to the specified key. The difference with .seek() is that if the specified key do not exist, this method will seek to key that lexicographically precedes it instead.

§Examples
use rocksdb::{DB, Options};

let path = "_path_for_rocksdb_storage8";
{
    let db = DB::open_default(path).unwrap();
    let mut iter = db.raw_iterator();

    // Read the last key that starts with 'a'
    iter.seek_for_prev(b"b");

    if iter.valid() {
        println!("{:?} {:?}", iter.key(), iter.value());
    } else {
        // There are no keys in the database
    }
}
let _ = DB::destroy(&Options::default(), path);
Source

pub fn next(&mut self)

Seeks to the next key.

Source

pub fn prev(&mut self)

Seeks to the previous key.

Source

pub fn key(&self) -> Option<&[u8]>

Returns a slice of the current key.

Source

pub fn value(&self) -> Option<&[u8]>

Returns a slice of the current value.

Source

pub fn item(&self) -> Option<(&[u8], &[u8])>

Returns pair with slice of the current key and current value.

Trait Implementations

Source§

impl<'a, D: DBAccess> Drop for DBRawIteratorWithThreadMode<'a, D>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a, D: DBAccess> Send for DBRawIteratorWithThreadMode<'a, D>

Source§

impl<'a, D: DBAccess> Sync for DBRawIteratorWithThreadMode<'a, D>