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

Implementations§

source§

impl<'a> DBRawIterator<'a>

source

pub fn valid(&self) -> bool

Returns true if the iterator is valid.

source

pub fn seek_to_first(&mut self)

Seeks to the first key in the database.

Examples
use ckb_rocksdb::prelude::*;

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
}
source

pub fn seek_to_last(&mut self)

Seeks to the last key in the database.

Examples
use ckb_rocksdb::prelude::*;

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
}
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 ckb_rocksdb::prelude::*;

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
}
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 ckb_rocksdb::prelude::*;

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
}
source

pub fn next(&mut self)

Seeks to the next key.

Returns true if the iterator is valid after this operation.

source

pub fn prev(&mut self)

Seeks to the previous key.

Returns true if the iterator is valid after this operation.

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.

Trait Implementations§

source§

impl<'a> Drop for DBRawIterator<'a>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'a> From<DBIterator<'a>> for DBRawIterator<'a>

source§

fn from(iter: DBIterator<'a>) -> DBRawIterator<'a>

Converts to this type from the input type.
source§

impl<'a> Sync for DBRawIterator<'a>

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.

use ckb_rocksdb::prelude::*;

let path = "_path_for_rocksdb_storage4";

let db = DB::open_default(&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();
}

// Reverse iteration from key
// Note, use seek_for_prev when reversing because if this key doesn't exist,
// this will make the iterator start from the previous key rather than the next.
iter.seek_for_prev(b"my key");
while iter.valid() {
    println!("Saw {:?} {:?}", iter.key(), iter.value());
    iter.prev();
}

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for DBRawIterator<'a>

§

impl<'a> !Send for DBRawIterator<'a>

§

impl<'a> Unpin for DBRawIterator<'a>

§

impl<'a> !UnwindSafe for DBRawIterator<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.