pub struct Table {
caption: String,
array: Vec<Vec<String>>,
}Expand description
A flexible table of arbitrary number of rows and columns, with a caption to describe the table within the process
Fields§
§caption: StringDescriptive string to display alongside the table
array: Vec<Vec<String>>The complete array of table data, with the Vec<Vec<>> representing Row<Col<>>
Example: to access the entire header (first) row of the table
array[0]
Example: to access the 8th column of the 10th row of the table
array[9][7]
All data in the table are stored as strings, as the ultimate destination for these data are in a formatted process document’s HTML text. These data are not intended to be numerically manipulated from this Table structure, but rather the assumption is that all of the numerical processing is already complete when these data are read into this structure.
Implementations§
Source§impl Table
Public “get” functions give access to the private fields. Private “set/add” functions are used within this module to construct the fields from a “new” Table struct.
impl Table
Public “get” functions give access to the private fields. Private “set/add” functions are used within this module to construct the fields from a “new” Table struct.
Sourcepub fn new() -> Table
pub fn new() -> Table
Empty string for the default caption, and an empty array for the default table data
Sourcepub fn get_caption(&self) -> &String
pub fn get_caption(&self) -> &String
Return reference to the table caption
Sourcefn set_caption(&mut self, caption: &str)
fn set_caption(&mut self, caption: &str)
Change the table caption field
Sourcepub fn get_size(&self) -> (usize, usize)
pub fn get_size(&self) -> (usize, usize)
Return a tuple with the number of rows and the number of columns in the table data array.
Assumptions:
- if there are zero rows, there are zero columns
- the number of columns in the first row is the number of columns that should be in every row
Sourcepub fn get_row(&self, row_num: usize) -> Vec<String>
pub fn get_row(&self, row_num: usize) -> Vec<String>
Return a vector with all cell contents for an indexed row number.
Example: to return the contents of the first row,
my_table.get_row(0)
Example: to return the conents of the 10th row,
my_table.get_row(9)
Sourcefn add_row(&mut self, row: Vec<String>)
fn add_row(&mut self, row: Vec<String>)
Append the bottom of the table data array with another row of data.
Assumptions:
- if this is the first row to be pushed, then it has the correct number of columns
- if this is not the first row, then columns will be added from left-to-right until the correct number of columns is reached
- if this new row has fewer than the correct number of columns, empty strings will fill in the righthand columns until the correct number is achieved