Trait TableViewer

pub trait TableViewer<R> {
    type Error;

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

    // Provided methods
    fn view_rt(&self, table: Tables) -> Result<R, Self::Error> { ... }
    fn view_dupsort<T>(&self) -> Result<R, Self::Error>
       where T: DupSort { ... }
}
Available on crate feature provider only.
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_api::{
    table::{DupSort, Table},
    TableViewer, Tables,
};

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§

type Error

The error type returned by the viewer.

Required Methods§

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

Operate on the table in a generic way.

Provided Methods§

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

Calls view with the correct table type.

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

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§