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.

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§