Skip to main content

derive_deftly_template_ItemValueEncodable

Macro derive_deftly_template_ItemValueEncodable 

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

Derive ItemValueEncodable

Fields in the struct are emitted as keyword line arguments, in the order they appear in the struct.

§Field type

Each field should be:

  • impl ItemArgument (one argument),
  • Option<impl ItemArgument> (one optional argument), or
  • Vec<impl ItemArgument + EncodeOrd> (zero or more arguments).
  • BTreeSet<impl ItemArgument> (zero or more arguments).

ItemArgument can be implemented via impl Display, by writing impl NormalItemArgument.

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

§Top-level attributes:p

  • `#[deftly(netdoc(no_extra_args))]:

    Ignored. (Obviously, the encoder never emits arguments that aren’t in the document struct.)

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

    (May not be combined with #[deftly(netdoc(rest))].)

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

    Currently implemented only as a placeholder

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

§Field-level attributes:

  • `#[deftly(netdoc(rest))]:

    The field is the whole rest of the line. Must come after any other normal argument fields. Only allowed once.

    The field type must implement ToString (normally, via Display). (I.e. Vec , Option etc., are not allowed, and ItemArgumen is not used.)

  • `#[deftly(netdoc(object))]:

    The field is the Object. It must implement ItemObjectEncodable. (or be Option<impl ItemObjectEncodable>).

    Only allowed once.

  • `#[deftly(netdoc(object(label = “LABEL”)))]:

    Sets the expected label for an Object. If not supplied, uses ItemObjectEncodable::label.

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

    Instead of ItemArgument, the argument is encoded with MODULE::write_arg_onto, which must have the same signature as ItemArgument::write_arg_onto.

    With #[deftly(netdoc(rest))], MODULE::fmt_args_rest replaces Display::fmt.

    With #[deftly(netdoc(object))], uses MODULE::write_object_onto instead of tor_netdoc::Writeable::write_onto. LABEL must also be specified unless the object also implements ItemObjectEncodable.

  • `#[deftly(netdoc(sig_hash = HASH_METHOD))]:

    TODO NETDOC ENCODE. Encoding of signed documents is not yet implemented.

  • `#[deftly(netdoc(skip))]:

    Do not encode this field.

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