Expand description
A model type’s storage contract as data.
What a record does with its fields — read them, write them, compare them,
edit, check and describe them — is the same walk for every record, over
each field’s own type. #[derive(Model)] describes a record as a table
of its fields (ResourceDesc) and three small functions reaching into it
(a field by position, the same mutably, and building one from its
fields), and every Model operation of a record is one function here,
compiled once into the runtime. A field’s type is reached through
its ModelTable: the type’s Model functions with the type erased,
built once per type, and for the types this crate defines, once.
Structs§
- Check
Reads - What a record’s own check reads: an edit that touches none of it cannot break the invariant, so the record is not read again to check it.
- Field
Desc - One field of a record, as
ResourceDesclists it. - ItemOps
- A collection type’s
ItemSourcefunctions, its type erased. - Item
OpsOf - The
ItemOpsof a collection type. - Json
Desc - A type stored whole through its serde form: as one JSON string, last
writer winning (
json_model!), or as that form’s maps, lists and scalars (value_model!). - JsonOf
- The serde functions of a type stored as JSON text.
- MapDesc
- What the table of a map of string keys reaches into one with.
- MapIn
- The
MapDescof the mapMof string keys toTs: aBTreeMap<String, T>(MapOf) or aMap, stored alike. - Model
Ops - A model type’s
Modelfunctions, its type erased. Each takes the table it was reached through, which for a record carries itsResourceDesc. A value is handed over as&dyn Anyof the type; a value made is put into an&mut dyn AnyofOptionof the type. - Model
Table - A model type as data: its erased
Modelfunctions, what it is (a record’s fields), and what it holds (a collection’s items). - Option
Desc - What
Option<T>’s table reaches into one with. - Option
Of - The
OptionDescofOption<T>. - OwnCheck
- A record’s own invariant (
#[model(check = path)]). - Resource
Desc - A record type as
#[derive(Model)]describes it. See the module docs. - Run
- A value of a type whose table does the work (
Model::to_jsonof anOption, aCollection): the type’s functions as the table runs them. - TableOf
- The table of
T, from its ownModelfunctions. - Unit
Desc - A
#[derive(Model)]enum of unit variants, each stored as its name. - ValueOf
- The serde functions of a
value_model!type, stored as its JSON form’s maps, lists and scalars. - VecDesc
- What
Vec<T>’s table reaches into one with. - VecOf
- The
VecDescofVec<T>.
Statics§
- ATOM_
STRING - The table of a
Stringstored whole, last writer winning (#[model(atom)]): an id or a name two people setting at once must not interleave. - JSON_
OPS - The functions of every type stored as JSON text.
- MAP_OPS
- The functions of every map of string keys: a map, one key per entry.
- OPTION_
OPS - The functions of every
Option:Noneis an absent key (or a null list element). - RESOURCE_
OPS - The functions of every record, over its
ResourceDesc. - UNIT_
OPS - The functions of every enum of unit variants.
- VEC_OPS
- The functions of every
Vec: a list of values.
Traits§
- Atomic
- A type
#[model(atom)]stores whole: one value, last writer wins, never merged part by part. A colour, a name from a list or an encoded path merged by character or element reads as no value at all. - Field
Source - Where a record being built takes its fields from, one after the other.
- List
Items - A list’s items, whatever their type.
- MapEntries
- A map’s entries, whatever their value type.
- Published
Items - A collection whose items are published: its items’ type’s table.
Functions§
- check
Model::checkof a record: its own invariant, then its fields’.- collect_
text Model::collect_textof a record.- diff
Model::diffof a record: each field that is not read-only, at its key. A field that would store as it is (Model::stores_as) has nothing to submit and is passed over, compared in memory: no path made for it, nothing turned into JSON. The path of a field compared further is made once, in one buffer.- diff_
into Model::diffof a record into edits of the recordE.- edit
Model::editof a record.- edit_
fields Fields::edit_fieldsof a record: a field segment routes the edit to its field; asetof the record replaces it whole; the record’s own check runs after.- empty_
of - An empty
OptionofT. - filled
- The value a record function put into
out. - for_
view - Call
readas a view’s reader reads: every#[model(demanded)]field it meets reads as its missing value, unread, until a view demands the item holding it and the resource’sloadreads that item whole. A read outside it reads every field as stored. - from_
json Model::from_jsonof a record, put intoout.- get_at
Model::get_atof a record.- holds_
nested_ items - Whether the record
value(described byrecord) holds an item at the end ofpath: collection fields by their Rust names, the outer ones looked into item by item over their first published page, as a publication lists them. - item_
collection_ sizes Fields::item_collection_sizesof a record.- item_
collections Fields::item_collectionsof a record: each collection field’s first page, then the collections inside their items.- item_
fields - The collection fields of published items a model of the table
tableholds, by name: where an item’s id (<kind>/<field>/<item>) may stand, read from the table alone. - item_
holds - Whether the collection field
nameholds the itemid, counting one it keeps out because it no longer reads: the check an action makes before it resolves a reference, so one that already names the id costs a scan of the ids alone. - item_
id_ any - Whether
referenceis the id of an item of any of the record’s collections: an action that names one may hold it in a collection other than the one its parameter is named after (item_named). - item_
json - What the published part of a record
resource_idnames holds, as its own model’s JSON ([Model::to_json]): the document read of an item of a collection, or of a field of one (an issue’s body), whatever their types, found inrecord(of the tabletable) by the steps<kind>/<field>/<item>,…/<field>/<item>for an item of a collection inside an item, and a last…/<field>for a field of the item reached. - item_
label Fields::item_labelof a record.- item_
named - Resolve
referenceto an item of the collection fieldname. - item_
named_ as item_namedin the wordswhatnames the items by —("project or area", "projects and areas")where the field’s own name is not what the app calls them — the field’s words when it isNone.- item_
search Fields::item_searchof a record.- label
Model::labelof a record: what itslabel = pathnames it, else the texts of its label fields joined by spaces, else its#[model(label)]field.- load
Model::loadof a record, put intoout.- missing
Model::missingof a record, put intoout.- names_
item - Whether
resource_idnames an item of a collection of published items in a record of the tabletableand kindkind, an item inside an item included, rather than a part of an item (an issue’s body, a channel’s call): what may be opened as an item. - op_
coalesces Model::op_coalescesof a record.- op_
continuable Model::op_continuableof a record.- op_
describe Model::op_describeof a record.- op_
lands Model::op_landsof a record.- op_
schemas Model::op_schemasof a record: only a field whose type has a vocabulary of its own is visited.- put
- Put
valueintoout, anOptionof its type. - put_
variant - Put
variantintoout, anOptionof its enum. - read_
fields Fields::read_fields, put intoout: every stored field read in one walk of the map.- reads_
item - Whether
resource_idnames a partitem_jsonreads in a record of the tabletableand kindkind: each step an item of a collection of published items, or a last field, of the record the step before reached. Decided from the tables alone, so offering the read costs no read. - reads_
on_ demand - Whether a value of
tableholds a#[model(demanded)]field anywhere (in its fields, their collections’ items, and theirs): whether what a view’s reader holds of it may be less than the document holds. - refresh
Model::refreshof a record.- refresh_
fields Fields::refresh_fieldsof a record: a map changed all over is read anew, else each touched field.- replace_
of - Swap the
Tinfilled, anOptionof it, withtarget:filledthen holds whattargetheld, dropped with it. - resource_
items - Every item the record
tablenames holds, by the collection field holding it: the id and the label each item is offered under, in the order the collection keeps them. Nothing is left out:item_collectionsis the page a publication carries, which a record with thousands of items is not. - set_
variant - Set
targettovariant. - store
Model::storeof a record. One whose map is made now is made with every field that can be at once ([fresh_fields]): twenty fields are one batch, not twenty writes each looking up its key first.- store_
changed Model::store_changedof a record.- stores_
as Model::stores_asof a record.- take
- The next field of
source, aT. - take_or
- The next field of
source, aT, or whatrepairderives for it when the document holds none: a field declared#[model(default = ..)], so a record missing it (written by an older app, or half-made by an edit that raced its deletion) still reads, and the next whole write stores it. - to_json
Model::to_jsonof a record.- unit_
schema Model::value_schemaof an enum of the variantsnames.- unwrap_
of - The
Tin a filledOptionof it. - whole
- Call
readreading every field as stored, inside a read for a view too: what a resource’sloadreads of the items a view demands. - write_
changed_ fields Fields::write_changed_fieldsof a record: each field written aswrite_key_changedwrites it.- write_
fields Fields::write_fieldsof a record.
Type Aliases§
- MapOf
- The
MapDescofBTreeMap<String, T>. - Read
Resource - Read a record, boxed, from the map it is stored in.