Skip to content

Commit 7d93744

Browse files
authored
der: add docs for Error and ErrorKind (#2058)
* der: add docs for `Error` and `ErrorKind` * der: reader.error(..) example
1 parent 3ee0028 commit 7d93744

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

der/src/error.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ use crate::pem;
1515
pub type Result<T> = core::result::Result<T, Error>;
1616

1717
/// Error type.
18+
///
19+
/// ## Example
20+
/// ```
21+
/// use der::{Decode, ErrorKind, Reader};
22+
///
23+
/// struct MyDecodable;
24+
///
25+
/// impl<'a> Decode<'a> for MyDecodable {
26+
/// type Error = der::Error;
27+
///
28+
/// fn decode<R: Reader<'a>>(reader: &mut R) -> Result<Self, der::Error> {
29+
/// Err(reader.error(ErrorKind::OidMalformed))
30+
/// }
31+
/// }
32+
/// ```
1833
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
1934
pub struct Error {
2035
/// Kind of error.
@@ -162,6 +177,15 @@ impl From<time::error::ComponentRange> for Error {
162177
}
163178

164179
/// Error type.
180+
///
181+
/// # Example
182+
/// ```
183+
/// use der::{asn1::OctetStringRef, Decode, ErrorKind};
184+
///
185+
/// let err = <&OctetStringRef>::from_der(&[0x04, 0x80, 0x00]).unwrap_err();
186+
///
187+
/// assert_eq!(err.kind(), ErrorKind::IndefiniteLength);
188+
/// ```
165189
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
166190
#[non_exhaustive]
167191
pub enum ErrorKind {

0 commit comments

Comments
 (0)