Macro match_continuation

Source
macro_rules! match_continuation {
    (
        continuation $name:ident<$lt:lifetime>($input_type:ty, spec $spec_input_type:ty) {
            $(
                $value:expr, spec $spec_value:expr => $variant:ident, $combinator_type:ty, $combinator:expr,
            )*

            _ => $last_variant:ident, $last_combinator_type:ty, $last_combinator:expr,

            $(,)?
        }
    ) => { ... };
}
Expand description

Generate a continuation that matches the input against a set of values and for each value, the result is parsed with different a combinator and stored in the suitable variant.

This generates the following types:

  • [< $name Cont >]: a continuation struct to be used in Depend
  • [< Spec $name Value >]: the spec result enum
  • [< $name Value >]: the normal result enum
  • [< $name ValueOwned >]: the owned result enum

Example:

match_continuation! {
    continuation ExtensionParam<'a>(ObjectIdentifierValue, spec SpecObjectIdentifierValue) {
        oid!(2, 5, 29, 35), spec spec_oid!(2, 5, 29, 35) => AuthorityKeyIdentifier, ASN1<OctetString>, ASN1(OctetString),
        _ => Other, ASN1<OctetString>, ASN1(OctetString),
    }
}