Derive Macro der::Choice

source ·
#[derive(Choice)]
{
    // Attributes available to this derive:
    #[asn1]
}
Available on crate feature derive only.
Expand description

Derive the Choice trait on an enum.

This custom derive macro can be used to automatically impl the Decode and Encode traits along with the Choice supertrait for any enum representing an ASN.1 CHOICE.

The enum must consist entirely of 1-tuple variants wrapping inner types which must also impl the Decode and Encode traits. It will will also generate From impls for each of the inner types of the variants into the enum that wraps them.

Usage

// NOTE: requires the `derive` feature of `der`
use der::Choice;

/// `Time` as defined in RFC 5280
#[derive(Choice)]
pub enum Time {
    #[asn1(type = "UTCTime")]
    UtcTime(UtcTime),

    #[asn1(type = "GeneralizedTime")]
    GeneralTime(GeneralizedTime),
}

#[asn1(type = "...")] attribute

See toplevel documentation for the der_derive crate for more information about the #[asn1] attribute.