cuprate_database

Trait DatabaseIter

Source
pub trait DatabaseIter<T: Table> {
    // Required methods
    fn get_range<'a, Range>(
        &'a self,
        range: Range,
    ) -> Result<impl Iterator<Item = Result<T::Value, RuntimeError>> + 'a, RuntimeError>
       where Range: RangeBounds<T::Key> + 'a;
    fn iter(
        &self,
    ) -> Result<impl Iterator<Item = Result<(T::Key, T::Value), RuntimeError>> + '_, RuntimeError>;
    fn keys(
        &self,
    ) -> Result<impl Iterator<Item = Result<T::Key, RuntimeError>> + '_, RuntimeError>;
    fn values(
        &self,
    ) -> Result<impl Iterator<Item = Result<T::Value, RuntimeError>> + '_, RuntimeError>;
}
Expand description

Database (key-value store) read-only iteration abstraction.

These are read-only iteration-related operations that can only be called from DatabaseRo objects.

§Hack

This is a HACK to get around the fact DatabaseRw tables cannot safely return values returning lifetimes, as such, only read-only tables implement this trait.

Required Methods§

Source

fn get_range<'a, Range>( &'a self, range: Range, ) -> Result<impl Iterator<Item = Result<T::Value, RuntimeError>> + 'a, RuntimeError>
where Range: RangeBounds<T::Key> + 'a,

Get an Iterator of value’s corresponding to a range of keys.

For example:

// This will return all 100 values corresponding
// to the keys `{0, 1, 2, ..., 100}`.
self.get_range(0..100);

Although the returned iterator itself is tied to the lifetime of &'a self, the returned values from the iterator are owned.

Although the returned iterator itself is tied to the lifetime of &self, the returned values from the iterator are owned.

§Errors

The construction of the iterator itself may error.

Each iteration of the iterator has the potential to error as well.

Source

fn iter( &self, ) -> Result<impl Iterator<Item = Result<(T::Key, T::Value), RuntimeError>> + '_, RuntimeError>

Get an Iterator that returns the (key, value) types for this database. Although the returned iterator itself is tied to the lifetime of &self, the returned values from the iterator are owned.

§Errors

The construction of the iterator itself may error.

Each iteration of the iterator has the potential to error as well.

Source

fn keys( &self, ) -> Result<impl Iterator<Item = Result<T::Key, RuntimeError>> + '_, RuntimeError>

Get an Iterator that returns only the key type for this database. Although the returned iterator itself is tied to the lifetime of &self, the returned values from the iterator are owned.

§Errors

The construction of the iterator itself may error.

Each iteration of the iterator has the potential to error as well.

Source

fn values( &self, ) -> Result<impl Iterator<Item = Result<T::Value, RuntimeError>> + '_, RuntimeError>

Get an Iterator that returns only the value type for this database. Although the returned iterator itself is tied to the lifetime of &self, the returned values from the iterator are owned.

§Errors

The construction of the iterator itself may error.

Each iteration of the iterator has the potential to error as well.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§