Skip to content

Commit

Permalink
der: Add documentation for the #[asn1(error)] attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
turbocool3r committed Oct 9, 2024
1 parent 3aaab2d commit 08f5a35
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions der_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@
//! The default is `EXPLICIT`, so the attribute only needs to be added when
//! a particular module is declared `IMPLICIT`.
//!
//! ### `#[asn1(error = ...)]` attribute: custom error types for decoding
//!
//! By default generated `Decode` / `DecodeValue` implementations generated by macros
//! from this crate use `der::Error` as the generic `Error` parameter, but it's
//! possible to use a custom error type that implements `From<der::Error>` by using
//! this attribute.
//!
//! Note that [`Choice`] puts more restrictions on the error type: during decoding
//! for each enum variant the type in its `#[asn1(type = "...")]` attribute (let's
//! call it `T`) is constructed and then converted to the actual variant's type
//! (this one will be `U`) using the `TryInto` trait. That means that for each enum
//! variant's type `U` the custom error type must implement
//! `From<<U as TryFrom<T>>::Error>`. Since `U` and `T` types are usually the same
//! implementing `From<Infallible>` should do it.
//!
//! ## Field-level attributes
//!
//! The following attributes can be added to either the fields of a particular
Expand Down

0 comments on commit 08f5a35

Please sign in to comment.