derive_deftly_template_NetdocEncodable

Macro derive_deftly_template_NetdocEncodable 

Source
macro_rules! derive_deftly_template_NetdocEncodable {
    ({ $($driver:tt)* } [$($aoptions:tt)*] ($($future:tt)*) $($tpassthrough:tt)*) => { ... };
    ($($wrong:tt)*) => { ... };
}
Expand description

Derive NetdocEncodable for a document (or sub-document)

§Expected input structure

Should be applied named-field struct, where each field is an Item which may appear in the document, or a sub-document.

The first field will be the document’s intro Item. The output Keyword for each Item will be kebab-case of the field name.

§Field type

Each field must be

  • impl ItemValueEncodable for an “exactly once” field,
  • Vec<T: ItemValueEncodable> for “zero or more”, or
  • BTreeSet<T: ItemValueEncodable + Ord>, or
  • Option<T: ItemValueEncodable> for “zero or one”.

We don’t directly support “at least once”; if the value is empty, the encoder will produce a structurally correct but semantically invalid document.

(Multiplicity is implemented via types in the [multiplicity] module, specifically [MultiplicitySelector] and [MultiplicityMethods].)

§Signed documents

TODO NETDOC ENCODE this is not yet supported.

§Top-level attributes:

  • #[deftly(netdoc(signatures))]:

    This type is the signatures section of another document. TODO NETDOC ENCODE This is not yet supported, and will fail to compile.

  • #[deftly(netdoc(debug))]:

    Currently implemented only as a placeholde

    The generated implementation may in future generate copious debug output to the program’s stderr when it is run. Do not enable in production!

§#[deftly(netdoc(doctype_for_error = "EXPRESSION"))]:

Ignored. (The encoder does not report errors this way.)

Accepted for alignment with NetdocParseable, so that a struct which only conditionally derives NetdocParseable does not need to conditionally mark this attribute.

§Field-level attributes:

  • #[deftly(netdoc(keyword = STR))]:

    Use STR as the Keyword for this Item.

  • #[deftly(netdoc(single_arg))]:

    The field type implements ItemArgument, instead of ItemValueEncodable, and is encoded as if (FIELD_TYPE,) had been written.

  • #[deftly(netdoc(with = "MODULE"))]:

    Instead of ItemValueEncodable, the item is parsed with MODULE::write_item_value_onto, which must have the same signature as ItemValueEncodable::write_item_value_onto.

    (Not supported for sub-documents, signature items, or field collections.)

  • #[deftly(netdoc(flatten))]:

    This field is a struct containing further individual normal fields. The Items for those individual fields appear in this outer document here, so interspersed with other normal fields.

    The field type must implement NetdocEncodableFields.

  • #[deftly(netdoc(subdoc))]:

    This field is a sub-document. The value type T must implment NetdocEncodable instead of ItemValueEncodable.

    The field name is not used for parsging; the sub-document’s intro keyword is used instead.

§#[deftly(netdoc(default))]:

Ignored. (The encoder always encodes the field, regardless of the value.)

Accepted for alignment with NetdocParseable.

§Example

TODO NETDOC ENCODE provide an example when signatures are implemented.

This is a derive_deftly template. Do not invoke it directly. To use it, write: #[derive(Deftly)] #[derive_deftly(NetdocEncodable)].