Trait simple_tables::Table [−][src]
pub trait Table<Row> where
Row: TableRow, {
Show 13 methods
fn new() -> Self;
fn from_vec(vec: &Vec<Row, Global>) -> Self;
fn get_rows(&self) -> &Vec<Row, Global>;
fn get_rows_mut(&mut self) -> &mut Vec<Row, Global>;
fn get_column_size<ColumnType>(
&self,
column: fn(&Row) -> ColumnType
) -> Option<usize>
where
ColumnType: ToString,
{ ... }
fn push(&mut self, row: Row) { ... }
fn insert_top(&mut self, row: Row) { ... }
fn insert(&mut self, i: usize, row: Row) { ... }
fn get_column<ColumnType>(
&self,
column: fn(&Row) -> ColumnType
) -> Vec<ColumnType, Global> { ... }
fn get_row_at(&self, i: usize) -> Option<&Row> { ... }
fn rm_row_at(&mut self, i: usize) -> Row { ... }
fn column_count(&self) -> usize { ... }
fn row_count(&self) -> usize { ... }
}
Expand description
A table should conform to this trait. Row
is the table’s row type.
Required methods
Creates a new Table
with an initial value for the rows
Returns an immutable reference to the rows of this table
fn get_rows_mut(&mut self) -> &mut Vec<Row, Global>
fn get_rows_mut(&mut self) -> &mut Vec<Row, Global>
Returns a mutable reference to the rows of this table
Provided methods
Gets the column size of a specific column. Requires that the column can be converted to a String.
Examples
let vec: Vec<TableRow> = vec![TableRow{id: 1000, name: String::from("Abc")}, TableRow{id: 2, name: String::from("Bd")}];
let table = MyTable::from_vec(&vec);
assert_eq!(3, table.get_column_size(|row| row.name.clone()).unwrap());
assert_eq!(4, table.get_column_size(|row| row.id).unwrap());
fn insert_top(&mut self, row: Row)
fn insert_top(&mut self, row: Row)
Inserts a new row at the top of the table (element 0)
Returns the column with the specific name
Example
let vec: Vec<TableRow> = vec![TableRow{id: 1, name: String::from("A")}, TableRow{id: 2, name: String::from("B")}];
let table = MyTable::from_vec(&vec);
let ids: Vec<u32> = table.get_column(|row| row.id);
assert_eq!(vec![1,2], ids);
fn get_row_at(&self, i: usize) -> Option<&Row>
fn get_row_at(&self, i: usize) -> Option<&Row>
Returns the row at the index