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>
where T::Value: ValueWithSubKey<SubKey = T::SubKey> { ... }
}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§
Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".