Expand description
Workbook layer for the truecalc spreadsheet engine: engine-locked workbook, worksheet, and cell value types with a canonical JSON serialization contract.
§Quick start
use truecalc_workbook::{Address, CellInput, EngineFlavor, RecalcContext, Value, Workbook, Worksheet};
// 1. Create a workbook locked to Google Sheets semantics.
let mut wb = Workbook::new(EngineFlavor::Sheets);
// 2. Add a sheet and write some cells.
wb.add_sheet(Worksheet::new("Budget")).unwrap();
let a1 = Address::from_a1("A1").unwrap();
let a2 = Address::from_a1("A2").unwrap();
let a3 = Address::from_a1("A3").unwrap();
wb.set("Budget", a1, CellInput::Literal(Value::Number(1000.0))).unwrap();
wb.set("Budget", a2, CellInput::Literal(Value::Number(500.0))).unwrap();
wb.set("Budget", a3, CellInput::Formula("=SUM(A1:A2)".to_string())).unwrap();
// 3. Recalculate to evaluate all formulas.
// timestamp_ms = Unix epoch in ms, tz = IANA timezone id, rng_seed = 0
let ctx = RecalcContext::new(1_780_000_000_000, "Etc/GMT", 0).unwrap();
let _changes = wb.recalc(&ctx);
assert_eq!(wb.get("Budget", a3).unwrap().value(), &Value::Number(1500.0));§Core concepts
-
Workbookis a value object:Clone + PartialEq + Hash, no hidden state or callbacks. Mutate withWorkbook::set/Workbook::clearand then drive recalc withWorkbook::recalcorWorkbook::recalc_incremental. -
Engine flavor (
EngineFlavor) is required at creation (Workbook::new) and immutable for the workbook’s lifetime. It controls formula semantics and the date serial system. -
RecalcContextpins volatile functions (NOW,TODAY) to a fixed UTC instant + IANA timezone. Same workbook + same context ⇒ byte-identical recomputed grid. -
CellInputis the discriminated input type forWorkbook::set:CellInput::Literal(value)orCellInput::Formula("=...".to_string()). Formula syntax is validated against the locked engine onset.
§Serialization
Workbook::to_json / Workbook::from_json implement the canonical
(RFC 8785 / JCS) serialization boundary — the byte-identical cross-surface
contract used across Rust, WASM, MCP, and REST surfaces.
§Related crates
truecalc-core: the formula parser and evaluator; theEnginetype and all formula evaluation lives there.
Modules§
- limits
- Resource limits — the single source of truth for the structural caps of
the scope ADR (
2026-06-07-workbook-v1-scope.md, Decision 5).
Structs§
- Address
- A parsed, in-bounds A1 address: 1-based
(row, column). - Cell
- An authored cell: a literal (
valueonly) or a formula (formula+value). Schema spec §4. - CellRef
- A fully resolved cell coordinate: a sheet (by its position-independent,
case-folded name) and an in-bounds
Address. - Change
- One cell whose evaluated value a recalc changed.
- Dependency
Graph - The dependency graph of a
Workbook: precedents and reverse-edge indexes derived from every formula cell viaextract_refs. - Named
Range - A workbook-scoped named range (schema spec §7).
- Range
Ref - A resolved rectangular range: a sheet (folded name) and an inclusive, top-left-first corner pair.
- Recalc
Context - The deterministic context a recalc evaluates against (scope ADR Decision 3).
- Resolved
- The effective value at an address after spill resolution (schema spec §5),
returned by
Workbook::resolved. - Spill
Rect - An in-bounds spill rectangle: the geometry of one anchor’s reconstructed
array. Cheap to copy; membership and indexing are
O(1). - Workbook
- An engine-locked spreadsheet workbook — a pure value object (no hidden state, no callbacks). Schema spec §2.
- Worksheet
- A named sheet holding a sparse cell grid (schema spec §3).
Enums§
- Cell
Input - What a
Workbook::setwrites into a cell: a literal value or a formula. - Engine
Flavor - Which spreadsheet product’s semantics the engine targets.
- Precedent
- One resolved precedent of a formula cell: what a single
Refin the formula points at, after sheet/name resolution. - Value
- An evaluated cell value — one of the seven types of schema spec §6.
- Workbook
Error - Errors from workbook value-type constructors and from
Workbook::from_json/Workbook::to_json.
Constants§
- BLOCKED_
SPILL_ ERROR - The Sheets blocked-spill error code (schema spec §12 edge-case 1: Sheets
reports a blocked array expansion as
#REF!). - CIRCULAR_
ERROR - The error a cell on (or downstream of) a circular dependency takes.
- SCHEMA_
VERSION - The schema version this library writes (schema spec §10). A string, not an integer: compared by exact match, never numerically.