Skip to main content

Module model

Module model 

Source
Expand description

How typed values live in a resource’s CRDT document.

Model is the whole storage contract: read a value out of the slot its parent found, and write a value back touching only what changed. Every write is a diff — an unchanged scalar writes nothing, a string is spliced rather than replaced, a keyed collection moves one order key rather than renumbering — so concurrent edits from members merge field by field and an action that changes nothing commits nothing.

Plain Rust types implement it here; #[derive(Model)] implements it for structs (a map, one key per field) and unit enums (a string). A resource type with its own storage layout implements it — or skips it and reads and writes the document itself, see crate::Resource.

Structs§

Atom
A string written whole: last writer wins. For identifiers, enum-like codes and short values where character merging would be wrong.

Enums§

Fresh
What a value writes under a key of a map made just now (Model::fresh): what can be made with that map in one batch is, so an item made whole costs the batch, not an operation and a lookup per field.
ModelError
Why a document could not be read as, or written from, a typed value.
Slot
Where a value is written: a key of a map, an existing list element, or a new list element inserted at an index.

Constants§

VARIANT_KEY
The key under which a data enum (#[derive(Model)] on an enum with fields) names its variant, beside the variant’s fields. No field may be stored under a key beginning with $, so it never collides with one.

Traits§

Fields
A Model stored as the fields of a map. #[derive(Model)] implements it for structs with named fields; a record resource keeps its fields at the document root.
LocatedAt
An error located at a key, as one function per value type rather than a closure per call.
Model
A typed value stored in a CRDT document. See the module docs.

Functions§

edit_whole
Model::edit for a value edited only as a whole: set at its own path, checked before it is written.
load_slot
T read from a slot read_slots found under key, or Model::missing: what read_key answers for that key.
read_key
Read the value under key of the map obj, or Model::missing.
read_slots
What each of keys holds in the map obj, read in one ordered walk of the map instead of one lookup per key: a lookup opens the map anew each time, and a struct of N fields read field by field opens it N times. The walk stops once every key is found. Each slot is exactly what ReadDoc::get answers for its key (the winning value of a conflict, a counter with its increments).
refresh_key
Bring target, read earlier from key of the map obj, up to date after the changes in delta: untouched keeps it, a written slot reads it again, a change inside the object it holds refreshes it in place.
storing_made
Whether the value Model::store is writing now was made with its map in one batch (Fresh::Made): it starts from the map as made, with no earlier content to keep.
take_slot
The slot at index of what read_slots returned, taken out of it, or an empty slot past its end. Not generic over the number of slots, so the derived reads share one copy.
write_key
Write value under key of the map obj.
write_key_changed
Write value under key of the map obj, which holds before: the operations write_key would write, without reading back what did not change. See Model::store_changed.

Type Aliases§

Doc
The document every resource lives in.
MapSlot
What a key of a map holds: its current value and the id of the op that wrote it, as ReadDoc::get returns them.