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. - Model
Error - 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
Modelstored 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. - Located
At - 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::editfor a value edited only as a whole:setat its own path, checked before it is written.- load_
slot Tread from a slotread_slotsfound underkey, orModel::missing: whatread_keyanswers for that key.- read_
key - Read the value under
keyof the mapobj, orModel::missing. - read_
slots - What each of
keysholds in the mapobj, 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 ofNfields read field by field opens itNtimes. The walk stops once every key is found. Each slot is exactly whatReadDoc::getanswers for its key (the winning value of a conflict, a counter with its increments). - refresh_
key - Bring
target, read earlier fromkeyof the mapobj, up to date after the changes indelta: 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::storeis 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
indexof whatread_slotsreturned, 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
valueunderkeyof the mapobj. - write_
key_ changed - Write
valueunderkeyof the mapobj, which holdsbefore: the operationswrite_keywould write, without reading back what did not change. SeeModel::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::getreturns them.