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§
Required Methods§
Provided Methods§
Sourcefn view_rt(&self, table: Tables) -> Result<R, Self::Error>
fn view_rt(&self, table: Tables) -> Result<R, Self::Error>
Calls view
with the correct table type.
Sourcefn view_dupsort<T: DupSort>(&self) -> Result<R, Self::Error>
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.