table::build
Building tables: the table! literal, records of a struct
(#[derive(Record)], or Record by hand), cells from Nabi values.
Traits
ToValueSource
pub trait ToValueA Nabi value that is one cell.
use table::ToValue;
assert(3.to_value() == table::Value::Int(3));
let x: f64 | none = none;
assert(x.to_value() == table::Value::Null);
The column type of this Nabi type.
RecordSource
pub trait RecordA struct whose values are rows: #[derive(table::Record)] writes it
from the fields (each a ToValue type), or implement it by hand.
#[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);
The column names, in field order.
The column types, in field order.
This record's cells, in field order.
Type aliases
CellSource
pub type Cell = i64 | f64 | bool | str | Date | DateTime | noneA 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).