Skip to content

Commit be8bde3

Browse files
authored
der: add doc example for Decode (#2064)
1 parent 7d93744 commit be8bde3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

der/src/decode.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,29 @@ use crate::EncodingRules;
2323
///
2424
/// When decoding fails, a [`Decode::Error`] type is thrown.
2525
/// Most ASN.1 DER objects return a builtin der [`Error`] type as [`Decode::Error`], which can be made from [`ErrorKind`].
26+
///
27+
/// ## Example
28+
///
29+
/// ```
30+
/// # #[cfg(all(feature = "alloc", feature = "std"))]
31+
/// # {
32+
/// use der::{Any, Decode, Reader};
33+
///
34+
/// /// Wrapper around Any, with custom foreign trait support.
35+
/// ///
36+
/// /// For example: serde Serialize/Deserialize
37+
/// pub struct AnySerde(pub Any);
38+
///
39+
/// impl<'a> Decode<'a> for AnySerde {
40+
/// type Error = der::Error;
41+
///
42+
/// fn decode<R: Reader<'a>>(reader: &mut R) -> der::Result<Self> {
43+
/// // calls impl Decode for Any
44+
/// Ok(Self(Any::decode(reader)?))
45+
/// }
46+
/// }
47+
/// # }
48+
/// ```
2649
#[diagnostic::on_unimplemented(
2750
note = "Consider adding impls of `DecodeValue` and `FixedTag` to `{Self}`"
2851
)]

0 commit comments

Comments
 (0)