Trait simple_tables::IdTable[][src]

pub trait IdTable<UidType, Row>: Table<Row> where
    UidType: PartialEq<UidType>,
    Row: TableRow
{ fn get_id_from_row(row: &Row) -> UidType; fn get_row(&self, uid: UidType) -> Option<&Row> { ... }
fn get_row_mut(&mut self, uid: UidType) -> Option<&mut Row> { ... }
fn get_row_index(&self, uid: UidType) -> Option<usize> { ... }
fn rm_row(&mut self, uid: UidType) -> Result<Row, TableError> { ... } }
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:
    the trait bound `MyTable: Table<TableRow>` is not satisfied
    you can simply ignore it given that you are using the table_row macro. Your IDE just doesn’t know the Table trait is already implemented for your struct. When you run your program, it will actually compile and run.

Required methods

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)]
struct MyTable {}

impl simple_tables::IdTable<i32, MyTableRow> for MyTable {
    fn get_id_from_row(row: i32) -> i32 {
        row.id
    }
}

Provided methods

Returns the row with the specific uid

Returns a mutable reference to a row

Returns the index of the row with the uid. Will be None if there is no row with this uid.

Removes the row with the uid from the table and returns the row. Returns an error if there is no table row with the uid.

Implementors