Trait simple_tables_core::Table [−][src]
pub trait Table<Row: TableRow> {
Show 13 methods
fn new() -> Self;
fn from_vec(vec: &Vec<Row>) -> Self;
fn get_rows(&self) -> &Vec<Row>;
fn get_rows_mut(&mut self) -> &mut Vec<Row>;
fn get_column_size<ColumnType: ToString>(
&self,
column: fn(_: &Row) -> ColumnType
) -> Option<usize> { ... }
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> { ... }
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
fn get_rows_mut(&mut self) -> &mut Vec<Row>
fn get_rows_mut(&mut self) -> &mut Vec<Row>
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)
fn get_column<ColumnType>(
&self,
column: fn(_: &Row) -> ColumnType
) -> Vec<ColumnType>
fn get_column<ColumnType>(
&self,
column: fn(_: &Row) -> ColumnType
) -> Vec<ColumnType>
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