Skip to main content

godspeed/
record.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Typed records: one table, and every rendering derived from it.
3//!
4//! # Why this is a re-export and not a wrapper
5//!
6//! Everything else in this crate wraps the SDK because there is something to translate: a capability
7//! to hold, an error to map onto one type, a protocol to hide. A [`Table`] has none of that. It is a
8//! bounded arena and some arithmetic - no syscall, no capability, no failure mode that a program
9//! should be told about differently. Wrapping twenty-three methods to change nothing would be exactly the
10//! speculative layer CLAUDE.md 26.2 warns against, and it would add a second name for one thing
11//! (Commandment III).
12//!
13//! So these are the SDK's types, re-exported here so that a program written against `gs` never has
14//! to name the lower layer to use them.
15//!
16//! # The one idea worth carrying away
17//!
18//! **The table is the truth; the grid and the JSON are views of it** (Commandment III). Build the
19//! table once, then render. Do not build a grid and a JSON separately from the same loop - the moment
20//! there are two constructions of one fact, they can disagree, and the one somebody reads will be
21//! whichever you did not check.
22//!
23//! ```ignore
24//! let mut t = gs::record::Table::new(&["name", "size"]);
25//! let n = t.intern(b"kernel.elf");
26//! t.add_row(&[n, gs::record::Value::Int(1930096)]);
27//! t.sort("size", true);
28//! t.to_grid(&mut sink);            // one view
29//! t.to_json(&mut sink);            // another view of the SAME table
30//! ```
31//!
32//! # Bounded, and it will tell you
33//!
34//! Fixed capacity, no heap (CLAUDE.md 26.6.1): [`REC_MAX_ROWS`] rows, [`REC_MAX_COLS`] columns, and a
35//! [`REC_ARENA`]-byte string arena. Past that, the row, column or string is dropped (a string that
36//! does not fit becomes `Value::Empty`) and [`Table::overflow`] returns true - which is there to be
37//! CHECKED. One case does NOT set it: an `add_row` given more values than the table has columns
38//! keeps the first `ncols` and silently ignores the rest. A truncated table that renders cleanly is a report that lies by
39//! omission, and the flag is how you avoid printing one.
40
41pub use godspeed_sdk::record::{
42    parse_predicate, AggErr, AggOp, RecordSink, Table, Value, REC_ARENA, REC_COL_NAME, REC_MAX_COLS,
43    REC_MAX_ROWS, REC_WIRE_MAGIC,
44};