#[derive(Model)]
{
// Attributes available to this derive:
#[model]
}
Expand description
Derive Model (and Fields for structs with named fields).
- a struct with named fields is a map, one key per field;
- a newtype struct is its inner value;
- an enum of unit variants is a string naming the variant; the variant
marked
#[default]is the value of an absent slot; - an enum whose variants carry fields is a map: the variant’s name under
$variantand each field under a key of its variant ($field/<variant>/<field>, a tuple variant’s fields named0,1, …), so edits of one variant merge field by field, a change of variant is last writer wins, and no variant reads a field another one wrote.
Field attributes: #[model(rename = "key")], #[model(skip)] (not
stored; the containing type’s Default on read), #[model(atom)] on a
String, an Id, a Vec or an Option of one (written whole, last writer
wins, as Atom is: a colour or a list of points two people set at once
is one of theirs, never a mix),
#[model(whole)] (read every part of a value that loads on demand,
rich text’s paragraphs), #[model(demanded)] (a view’s reader leaves it
unread, as its type’s missing value, until a view demands the item
holding it: an issue’s description and thread, which a list of thousands
of issues never shows), #[model(resource)] on a field whose type is a
resource with its own operations (rich text: published beneath the
record’s resource, an item’s or the record’s own, at <record>/<key>,
its actions applied as field edits; see tilo_resource::child), #[model(remove = "quiet")] on a collection whose items are cheap to
remove (removing one by field edit asks no confirmation),
#[model(default = expr)] (what the field reads as when the document
holds none: a required field with a sensible derivation, so an item
missing it still reads; the next whole write stores it),
#[model(trust = "sensitive")] (every edit of it asks for confirmation:
a change can expose the person), #[model(trust = "weakening")]
(it also crosses a security boundary: any change can weaken the person’s
security, so an agent or script acting for them needs their own grant)
and #[model(weaker = ..)] (only a change making it weaker than it is
now does: weaker = "higher" or "lower" for a number, with
weakest = N for the value weaker than any, such as a lock delay’s 0
for never; weaker = true or false for a switch; a list of values
from the strongest to the weakest for a choice), #[model(range = low..=high)] on a number and #[model(choices = expr)] on a text (what
the field may hold: published in its value’s schema and held by the
record’s own check, through every API).
Type attributes: #[model(check = path)] (its invariant, with
check_reads/check_items saying what it reads), #[model(label = "..")], #[model(defaults)] (the type’s Default is what each field
holds until changed, published with it) and #[model(field(name, options..))] (a field’s options given on the type, for a record whose
fields a shared macro writes).
A struct’s Model::SHAPE lists its stored fields, so layout-aware services
(History restore) reconcile it field by field.