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 the Copy, Default, uDebug, and uDisplay 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 the new method’s headers parameter. This value must be greater than zero.

Fields

  • headers - An array of M strings that are the column names for the data table.
  • data - An array of N rows of type T.
  • 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>

source

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.

source

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.

source

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.

source

pub fn erase(&mut self)

Erase the data table. The length of the table will be set to zero.

source

pub fn length(&self) -> usize

Get the length of the data table.

source

pub fn headers(&self) -> &[&'a str; M]

Get a reference to the headers of the data table.

source

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 - The ufmt::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 an i32. The mapping of the desired row value to the i32 is for display purposes.

Trait Implementations§

source§

impl<'a, T: Copy + Default + uDebug + uDisplay, const N: usize, const M: usize> uDebug for uDataTable<'a, T, N, M>

source§

fn fmt<W>(&self, f: &mut Formatter<'_, W>) -> Result<(), W::Error>where W: uWrite + ?Sized,

Formats the value using the given formatter
source§

impl<'a, T: Copy + Default + uDebug + uDisplay, const N: usize, const M: usize> uDisplay for uDataTable<'a, T, N, M>

source§

fn fmt<W>(&self, f: &mut Formatter<'_, W>) -> Result<(), W::Error>where W: uWrite + ?Sized,

Formats the value using the given formatter

Auto Trait Implementations§

§

impl<'a, T, const N: usize, const M: usize> RefUnwindSafe for uDataTable<'a, T, N, M>where T: RefUnwindSafe,

§

impl<'a, T, const N: usize, const M: usize> Send for uDataTable<'a, T, N, M>where T: Send,

§

impl<'a, T, const N: usize, const M: usize> Sync for uDataTable<'a, T, N, M>where T: Sync,

§

impl<'a, T, const N: usize, const M: usize> Unpin for uDataTable<'a, T, N, M>where T: Unpin,

§

impl<'a, T, const N: usize, const M: usize> UnwindSafe for uDataTable<'a, T, N, M>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.