packages

table::build

On this page

Building tables: the table! literal, records of a struct (#[derive(Record)], or Record by hand), cells from Nabi values.

Traits

ToValueSource

pub trait ToValue

A Nabi value that is one cell.

nabi
use table::ToValue;
assert(3.to_value() == table::Value::Int(3));
let x: f64 | none = none;
assert(x.to_value() == table::Value::Null);

RecordSource

pub trait Record

A struct whose values are rows: #[derive(table::Record)] writes it from the fields (each a ToValue type), or implement it by hand.

nabi
#[derive(table::Record)]
struct Trade { sym: str; qty: i64; px: f64; }

let t = table::record_table([Trade { sym: "A", qty: 10, px: 1.5 }, Trade { sym: "B", qty: 5, px: 2.0 }]);
assert(t.names() == ["sym", "qty", "px"]);
assert(t.row(1).f64("px") == 2.0);
  • fn names() -> List<str>§

    Source

    The column names, in field order.

  • fn dtypes() -> List<DType>§

    Source

    The column types, in field order.

  • fn cells(self) -> List<Value>§

    Source

    This record's cells, in field order.

Type aliases

CellSource

pub type Cell = i64 | f64 | bool | str | Date | DateTime | none

A cell as a list literal of table! writes it.

Functions

dtype_ofSource

pub fn dtype_of<T: ToValue>() -> DType

The column type of T.

record_tableSource

pub fn record_table<R: Record>(rs: List<R>) -> Table

A table with one row per record; the column types come from the struct, so an empty list still has the columns.

literalSource

pub fn literal(cols: List<(str, Column)>) -> Table

The table! literal's columns as a table; panics on columns of different lengths or repeated names, which are mistakes in the code.

literal_columnSource

pub fn literal_column(cells: List<Cell>) -> Column

A literal column from its cells; mixed kinds panic (a mistake in the code).