Table

Trait Table 

Source
pub trait Table<Row: TableRow> {
Show 13 methods // Required 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>; // Provided methods 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§

Source

fn new() -> Self

Creates a new empty Table

Source

fn from_vec(vec: &Vec<Row>) -> Self

Creates a new Table with an initial value for the rows

Source

fn get_rows(&self) -> &Vec<Row>

Returns an immutable reference to the rows of this table

Source

fn get_rows_mut(&mut self) -> &mut Vec<Row>

Returns a mutable reference to the rows of this table

Provided Methods§

Source

fn get_column_size<ColumnType: ToString>( &self, column: fn(&Row) -> ColumnType, ) -> Option<usize>

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());
Source

fn push(&mut self, row: Row)

Pushes a new row to the end of the table

Source

fn insert_top(&mut self, row: Row)

Inserts a new row at the top of the table (element 0)

Source

fn insert(&mut self, i: usize, row: Row)

Inserts a new row at index i

Source

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);
Source

fn get_row_at(&self, i: usize) -> Option<&Row>

Returns the row at the index

Source

fn rm_row_at(&mut self, i: usize) -> Row

Removes the row at the index and returns the row

Source

fn column_count(&self) -> usize

Source

fn row_count(&self) -> usize

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§