IdTable

Trait IdTable 

Source
pub trait IdTable<UidType: PartialEq, Row: TableRow>: Table<Row> {
    // Required method
    fn get_id_from_row(row: &Row) -> UidType;

    // Provided methods
    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§

Source

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

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

Provided Methods§

Source

fn get_row(&self, uid: UidType) -> Option<&Row>

Returns the row with the specific uid

Source

fn get_row_mut(&mut self, uid: UidType) -> Option<&mut Row>

Returns a mutable reference to a row

Source

fn get_row_index(&self, uid: UidType) -> Option<usize>

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

Source

fn rm_row(&mut self, uid: UidType) -> Result<Row, TableError>

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.

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§