Skip to main content

Module element

Module element 

Source
Expand description

Elements, which say what the nodes of a document mean, and the aspect map through which the rest of the library reads an element’s behavior.

An element is the value that says what a node means: a declaration with a stable dotted type name (ElementName, such as flm.heading or thm.exercise), identified by the element value itself (its allocation) and not by its name (ElementSpec). An element carries aspects: pieces of behavior attached to the element when a feature registers it, held in its AspectMap and read back through trait objects. A stage asks an element what it does through an aspect (“is this a block?”, “which reference points does this node carry?”) instead of matching its name. See elements and aspects; the aspects that the standard features use are defined in crate::model::aspects.

A feature declares a construct once, and that one declaration produces both the specification the parser uses and the element (ElementDef). Every node of every parsed tree carries its element in its node extension (FlmNodeExt), so element_of reads a node’s element without any lookup.

§Identity of an element

An element is identified by its element value, not by its name and not by a Rust type. \section and \subsection are two element values of the single type flm.heading, which differ in their data (ElementSpec::value). An element value is shared as Arc<ElementSpec>, and two handles denote the same element when they point at the same allocation (ElementSpec::same_value). A registry gives each registered element value a number of its own (ElemIdx) to index its lookup structures. Rust’s TypeId appears in this module only as the key of the aspect map.

§Items

  • ElementSpec — one element value: its type name, a description, its aspects and its data.
  • AspectMap — the aspects attached to one element, and AspectCollision, the error of attaching one aspect twice.
  • element_of and element_value — a node’s element, and that element’s data.
  • ElemIdx — a registry’s number for an element value.
  • AmbiguousElement — the error of looking up an element by a type name that several element values share.

Structs§

AmbiguousElement
The error of looking up an element value by a type name that several registered element values share.
AspectCollision
The error of attaching an aspect to an element that already has an implementation of that aspect.
AspectMap
The aspect implementations attached to one element, at most one per aspect, each stored under the aspect’s trait.
ElemIdx
The number a registry gives one element value, counted from zero.
ElementSpec
One element: the value that says what a node means, with a stable type name, a one-line description, the aspects attached to it and its own data.

Functions§

element_of
The element of the node node.
element_value
The data of the element of the node node, as a V.