Crate der_derive[][src]

Expand description

Custom derive support for the der crate.

This crate contains custom derive macros intended to be used in the following way:

  • Choice: map ASN.1 CHOICE to a Rust enum.
  • Message: map ASN.1 SEQUENCE to a Rust struct.

Note that this crate shouldn’t be used directly, but instead accessed by using the derive feature of the der crate.

Why not serde?

The der crate is designed to be easily usable in embedded environments, including ones where code size comes at a premium.

This crate (i.e. der_derive) is able to generate code which is significantly smaller than serde_derive. This is because the der crate has been designed with high-level abstractions which reduce code size, including trait object-based encoders which allow encoding logic which is duplicated in serde serializers to be implemented in a single place in the der crate.

This is a deliberate tradeoff in terms of performance, flexibility, and code size. At least for now, the der crate is optimizing for leveraging as many abstractions as it can to minimize code size.

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

This attribute can be used to specify the ASN.1 type for a particular enum variant or struct field.

It’s presently mandatory for all enum variants, even when using one of the ASN.1 types defined by this crate.

For structs, placing this attribute on a field makes it possible to decode/encode types which don’t directly implement the Decode/Encode traits but do impl From and TryInto and From for one of the ASN.1 types listed below (use the ASN.1 type keywords as the type):

Note: please open a GitHub Issue if you would like to request support for additional ASN.1 types.

Derive Macros

Derive the Choice trait on an enum.

Derive the Message trait on a struct.