Skip to main content

Table

Trait Table 

Source
pub trait Table:
    Any
    + Send
    + Sync
    + Default {
    // Required method
    fn absorb(&mut self, piece: Self);

    // Provided methods
    fn project(&self, cx: &dyn ProjectCx) -> SerialValue { ... }
    fn piece_class(&self) -> PieceClass { ... }
}
Expand description

The trait of a table’s value type.

A table is typed data that one stage writes beside the frozen trees and other stages read; its identity is its registered dotted name, never its Rust type, and that name is also a capability. See frozen trees and computed data for why computed data is kept in tables, and the module documentation for how names, value types and typed table keys relate.

A map keyed by node address and a map keyed by a symbolic name are the usual shapes of a table, but any value type can be one: a document-wide count is a table whose absorb adds.

To add a table, implement this trait on its value type, declare the table in a feature with FeatureBuilder::table (or FeatureBuilder::external_table for a table no stage writes), declare it as a write of the stage that produces it (StageDecl::writes) and as a read of each stage that reads it (Needs::reads), and export a TableName constant for its readers. A stage writes its part of the table through StageOut::table, and a later stage reads the whole table through StageCx::get.

The value type must implement Default: a stage’s table piece starts as the default value, and a stage that declared a write but produced nothing still installs a default (empty) table.

See also SingletonTable for a value type used by exactly one table, and TableType for the type-erased form of a value type.

Required Methods§

Source

fn absorb(&mut self, piece: Self)

Combines piece, a table piece produced by the same stage, into self.

The runner calls this when it folds one stage’s table pieces into the store: it keeps the first table piece and absorbs each following one into it, in the run’s order of the trees (Run::tree_order). The resulting table must therefore depend only on the table pieces and their order. The table type decides what happens on a collision: a table of labels, for example, records the duplicate so that a later check stage can report it.

Provided Methods§

Source

fn project(&self, cx: &dyn ProjectCx) -> SerialValue

Serializes the table as plain data, for the inspection dumps (crate::dump) and tests.

The default implementation returns a placeholder holding the short name of the Rust type, <TypeName>. A table with a readable serialized form overrides it and writes every node address, tree identifier or synthesized value it holds through cx; see ProjectCx.

Source

fn piece_class(&self) -> PieceClass

Classifies self, taken as a table piece: see PieceClass.

The runner calls this only on the table pieces produced during value catch-up. The default implementation returns NodeKeyed, which fits every table keyed by node address. A table keyed symbolically, or holding a document-wide value, returns Empty when it holds nothing and DocumentFact otherwise.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§