Derive Macro der_derive::Enumerated

source ·
#[derive(Enumerated)]
{
    // Attributes available to this derive:
    #[asn1]
}
Expand description

Derive decoders and encoders for ASN.1 Enumerated types on a C-like enum type.

§Usage

The Enumerated proc macro requires a C-like enum which impls Copy and has a #[repr] of u8, u16, or u32:

use der::Enumerated;

#[derive(Enumerated, Copy, Clone, Debug, Eq, PartialEq)]
#[repr(u32)]
pub enum CrlReason {
    Unspecified = 0,
    KeyCompromise = 1,
    CaCompromise = 2,
    AffiliationChanged = 3,
    Superseded = 4,
    CessationOfOperation = 5,
    CertificateHold = 6,
    RemoveFromCrl = 8,
    PrivilegeWithdrawn = 9,
    AaCompromised = 10
}

Note that the derive macro will write a TryFrom<...> impl for the provided #[repr], which is used by the decoder.