Trait engine_traits::iterable::Iterator[][src]

pub trait Iterator: Send {
    fn seek(&mut self, key: SeekKey<'_>) -> Result<bool>;
fn seek_for_prev(&mut self, key: SeekKey<'_>) -> Result<bool>;
fn prev(&mut self) -> Result<bool>;
fn next(&mut self) -> Result<bool>;
fn key(&self) -> &[u8];
fn value(&self) -> &[u8];
fn valid(&self) -> Result<bool>; fn seek_to_first(&mut self) -> Result<bool> { ... }
fn seek_to_last(&mut self) -> Result<bool> { ... } }

An iterator over a consistent set of keys and values.

Iterators are implemented for KvEngines and for Snapshots. They see a consistent view of the database; an iterator created by an engine behaves as if a snapshot was created first, and the iterator created from the snapshot.

Most methods on iterators will panic if they are not “valid”, as determined by the valid method. An iterator is valid if it is currently “pointing” to a key/value pair.

Iterators begin in an invalid state; one of the seek methods must be called before beginning iteration. Iterators may become invalid after a failed seek, or after iteration has ended after calling next or prev, and they return false.

Required methods

fn seek(&mut self, key: SeekKey<'_>) -> Result<bool>[src]

Move the iterator to a specific key.

When key is SeekKey::Start or SeekKey::End, seek and seek_for_prev behave identically. The difference between the two functions is how they behave for SeekKey::Key, and only when an exactly matching keys is not found:

When seeking with SeekKey::Key, and an exact match is not found, seek sets the iterator to the next key greater than that specified as key, if such a key exists; seek_for_prev sets the iterator to the previous key less than that specified as key, if such a key exists.

Returns

true if seeking succeeded and the iterator is valid, false if seeking failed and the iterator is invalid.

fn seek_for_prev(&mut self, key: SeekKey<'_>) -> Result<bool>[src]

Move the iterator to a specific key.

For the difference between this method and seek, see the documentation for seek.

Returns

true if seeking succeeded and the iterator is valid, false if seeking failed and the iterator is invalid.

fn prev(&mut self) -> Result<bool>[src]

Move a valid iterator to the previous key.

Panics

If the iterator is invalid

fn next(&mut self) -> Result<bool>[src]

Move a valid iterator to the next key.

Panics

If the iterator is invalid

fn key(&self) -> &[u8][src]

Retrieve the current key.

Panics

If the iterator is invalid

fn value(&self) -> &[u8][src]

Retrieve the current value.

Panics

If the iterator is invalid

fn valid(&self) -> Result<bool>[src]

Returns true if the iterator points to a key/value pair.

Loading content...

Provided methods

fn seek_to_first(&mut self) -> Result<bool>[src]

Short for seek(SeekKey::Start).

fn seek_to_last(&mut self) -> Result<bool>[src]

Short for seek(SeekKey::End).

Loading content...

Implementors

Loading content...