reth_db::tables

Trait TableViewer

source
pub trait TableViewer<R> {
    type Error;

    // Required method
    fn view<T: Table>(&self) -> Result<R, Self::Error>;

    // Provided methods
    fn view_rt(&self, table: Tables) -> Result<R, Self::Error> { ... }
    fn view_dupsort<T: DupSort>(&self) -> Result<R, Self::Error> { ... }
}
Expand description

The general purpose of this is to use with a combination of Tables enum, by implementing a TableViewer trait you can operate on db tables in an abstract way.

§Example

use reth_db::{TableViewer, Tables};
use reth_db_api::table::{DupSort, Table};

struct MyTableViewer;

impl TableViewer<()> for MyTableViewer {
    type Error = &'static str;

    fn view<T: Table>(&self) -> Result<(), Self::Error> {
        // operate on table in a generic way
        Ok(())
    }

    fn view_dupsort<T: DupSort>(&self) -> Result<(), Self::Error> {
        // operate on a dupsort table in a generic way
        Ok(())
    }
}

let viewer = MyTableViewer {};

let _ = Tables::Headers.view(&viewer);
let _ = Tables::Transactions.view(&viewer);

Required Associated Types§

source

type Error

The error type returned by the viewer.

Required Methods§

source

fn view<T: Table>(&self) -> Result<R, Self::Error>

Operate on the table in a generic way.

Provided Methods§

source

fn view_rt(&self, table: Tables) -> Result<R, Self::Error>

Calls view with the correct table type.

source

fn view_dupsort<T: DupSort>(&self) -> Result<R, Self::Error>

Operate on the dupsort table in a generic way.

By default, the view function is invoked unless overridden.

Object Safety§

This trait is not object safe.

Implementors§