Struct udatatable::uDataTable
source · pub struct uDataTable<'a, T: Copy + Default + uDebug + uDisplay, const N: usize, const M: usize> { /* private fields */ }
Expand description
The uDataTable
structure.
Generic Parameters
T
- The row type. This type must implement theCopy
,Default
,uDebug
, anduDisplay
traits.N
- The maximum number of rows in the data table. This value must be greater than zero. Note that the data table will be stored on the stack, so the maximum number of rows should be kept small.M
- The number of columns in the data table, or more specifically, the number of column names that will be passed to thenew
method’sheaders
parameter. This value must be greater than zero.
Fields
headers
- An array ofM
strings that are the column names for the data table.data
- An array ofN
rows of typeT
.length
- The number of rows of data that has been inserted into the able. This value will be between 0..N.
Implementations§
source§impl<'a, T: Copy + Default + uDebug + uDisplay, const N: usize, const M: usize> uDataTable<'a, T, N, M>
impl<'a, T: Copy + Default + uDebug + uDisplay, const N: usize, const M: usize> uDataTable<'a, T, N, M>
sourcepub fn new(headers: [&'a str; M]) -> Self
pub fn new(headers: [&'a str; M]) -> Self
Create a new data table with the specified headers passed in headers
. There should be M headers in the passed headers
array.
sourcepub fn get(&self, index: usize) -> Result<&T, uDataTableError>
pub fn get(&self, index: usize) -> Result<&T, uDataTableError>
Get a reference to the row at the specified index
. The `index`` must be less than the length of the table.
sourcepub fn append(&mut self, row: T) -> Result<&T, uDataTableError>
pub fn append(&mut self, row: T) -> Result<&T, uDataTableError>
Append a row to the data table. The length of the table will be increased by one. The row will be copied into the data table. The row must implement the Copy trait. If the length of the table is equal to N, then the row will not be appended and an error will be returned.
sourcepub fn plot<W>(&self, f: &mut W, value: fn(_: &T) -> i32)where
W: uWrite + ?Sized,
pub fn plot<W>(&self, f: &mut W, value: fn(_: &T) -> i32)where W: uWrite + ?Sized,
Plots the data table. The data table will be plotted with rows on the horizontal axis and values
on the vertical axis. The plot method will scan thrugh all the rows in th data table
with the passed value
function to determine the range of values to be plotted. The plot method will then
scale the values to fit in the display area. The plot method will display the range of values
on the vertical axis and the row index on the horizontal axis.
Arguments
f
- Theufmt::uWrite
object that the grph should be printed to.value
- A function that gets called on each row in the data table to determine the value from that row to plot. This function must take a reference to the row type and return ani32
. The mapping of the desired row value to thei32
is for display purposes.