Trait simple_tables::IdTable [−][src]
pub trait IdTable<UidType, Row>: Table<Row> where
Row: TableRow,
UidType: PartialEq<UidType>, {
fn get_id_from_row(row: &Row) -> UidType;
fn get_row(&self, uid: UidType) -> Option<&Row> { ... }
}Expand description
Defines a table with a unique identifier. This class should be implemented alongside the
Table trait.
When you have a table with a uid, this trait has to be implemented manually for now.
To implement
Notes
- If your IDE tells you following error when implementing this trait:you can simply ignore it given that you are using the
the trait bound `MyTable: Table<TableRow>` is not satisfiedtable_rowmacro. Your IDE just doesn’t know theTabletrait is already implemented for your struct. When you run your program, it will actually compile and run.
Required methods
fn get_id_from_row(row: &Row) -> UidType
fn get_id_from_row(row: &Row) -> UidType
Gets the uid from a row, this should be implemented manually (for now) for structs with uids.
Example
#[table_row]
struct MyTableRow {
id: i32,
name: String
}
#[table(rows = MyTableRow, uid = "id")]
struct MyTable {}
impl simple_tables::IdTable<i32, MyTableRow> for MyTable {
fn get_id_from_row(row: i32) -> i32 {
row.id
}
}