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

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.

§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.)

  • `#[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))], FUNCTION replaces <FIELD AS FromStr>::from_str.

    With #[deftly(netdoc(objecte))], 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 be discarded and replaced with [ErrorProblem::ObjectInvalidData`].

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

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

    This field is a document hash. The hash will be computed using HASH_METHOD, which will be resolved with sig_hash_methods::* in scope.

    fn HASH_METHOD(body: &SignatureHashInputs) -> HASH_FIELD_VALUE.

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