Skip to main content

derive_deftly_template_ItemValueParseable

Macro derive_deftly_template_ItemValueParseable 

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

Derive ItemValueParseable (or SignatureItemParseable)

Fields in the struct are parsed from the keyword line arguments, in the order they appear in the struct.

§Field type

Each field should be:

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

ItemArgumentParseable can be implemented via impl FromStr, by writing impl NormalItemArgument.

For Option or Vec, we expect that if there are any further arguments, they are for this field. So absence of any optional argument means absence of following arguments, and no arguments can follow a Vec.

Some Tor netdocs have optional arguments followed by other data, with unclear/ambiguous parsing rules. These cases typically require manual implementation of ItemValueParseable.

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

§Top-level attributes:

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

    Reject, rather than ignore, additional arguments found in the document which aren’t described by the struct.

  • `#[deftly(netdoc(signature(hash_accu = HASH_ACCU))]:

    This item is a signature item. SignatureItemParseable will be implemented instead of ItemValueParseable.

    HASH_ACCU is the type in which the hash(es) for this item will be accumulated, and must implement SignatureHashesAccumulator. It is used as SignatureItemParseable::HashAccu.

  • #[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!

  • #[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 FromStr. (I.e. Vec , Option etc., are not allowed, and ItemArgumentParseable is not used.)

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

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

    Only allowed once. If omittted, any object is rejected.

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

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

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

    Instead of ItemArgumentParseable, the argument is parsed with MODULE::from_args, which must have the same signature as ItemArgumentParseable::from_args.

    With #[deftly(netdoc(rest))], the argument is parsed with MODULE::from_args_rest, must have the signature fn from_args_rest(s: &str) -> Result<FIELD, _>). and replaces <FIELD as FromStr>::from_str.

    With #[deftly(netdoc(object))], uses MODULE::try_from which must have the signature fn(Vec<u8>) -> Result<OBJECT, _>; like TryFrom::<Vec>>::try_from. LABEL must also be specified unless the object also implements ItemObjectParseable. Errors from parsing will all be collapsed into [ErrorProblem::ObjectInvalidData`].

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

    Do not parse this field; fill it in with Default::default() instead.

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