Skip to main content

Module multiplicity

Module multiplicity 

Source
Expand description

Multiplicity of fields (Items and Arguments)

This module supports type-based handling of multiplicity, of Items (within Documents) and Arguments (in Item keyword lines).

It is for use by macros, rather than directly.

See also encode::multiplicity which is the corresponding module for encoding.

§Explanation

We use autoref specialisation to allow macros to dispatch to trait impls for Vec<T: ItemValueParseable>, Option<T> etc. as well as simply unadorned T.

We implement traits on a helper type struct MultiplicitySelector<Field>.

For Items we have trait ItemSetMethods.

ItemSetMethods is implemented for MultiplicitySelector<Field> for each supported Field. So, for MultiplicitySelector<T>, MultiplicitySelector<Option<T>>, and MultiplicitySelector<Vec<T>>. But, for just T, the impl is on &MultiplicitySelector<T>.

When methods on MultiplicitySelector are called, the compiler finds the specific implementation for MultiplicitySelector<Option<_>> or ..Vec<_>, or, failing that, derefs and finds the blanket impl on &MultiplicitySelector<T>.

For Arguments we have ArgumentSetMethods, and for Objects, ObjectSetMethods, which work similarly.

(We need separate traits for each of the kinds of netdoc element, for good support of inference in the derive macro. Type inference is particularly difficult during parsing, since we need the type information to flow from the field type, which is the destination to which a value is going to be stored.)

Structs§

DebugHelper 🔒
Helper type that allows us to implement Debug
MultiplicitySelector
Helper type that allows us to select an impl of ItemSetMethods etc.

Traits§

ArgumentSetMethods
Method for handling some multiplicity of Arguments
ItemSetMethods
Methods for handling some multiplicity of Items, during parsing
ObjectSetMethods
Method for handling some multiplicity of Objects