1use core::fmt;
2
3pub type Result<T, E = Error> = core::result::Result<T, E>;
5
6#[derive(Clone, Copy, Debug, Eq, PartialEq)]
8pub enum Error {
9 Overflow,
11 LeadingZero,
13 InputTooShort,
15 NonCanonicalSingleByte,
17 NonCanonicalSize,
19 UnexpectedLength,
21 UnexpectedString,
23 UnexpectedList,
25 ListLengthMismatch {
27 expected: usize,
29 got: usize,
31 },
32 Custom(&'static str),
34}
35
36#[cfg(feature = "std")]
37impl std::error::Error for Error {}
38
39impl fmt::Display for Error {
40 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 match self {
42 Self::Overflow => f.write_str("overflow"),
43 Self::LeadingZero => f.write_str("leading zero"),
44 Self::InputTooShort => f.write_str("input too short"),
45 Self::NonCanonicalSingleByte => f.write_str("non-canonical single byte"),
46 Self::NonCanonicalSize => f.write_str("non-canonical size"),
47 Self::UnexpectedLength => f.write_str("unexpected length"),
48 Self::UnexpectedString => f.write_str("unexpected string"),
49 Self::UnexpectedList => f.write_str("unexpected list"),
50 Self::ListLengthMismatch { got, expected } => {
51 write!(f, "unexpected list length (got {got}, expected {expected})")
52 }
53 Self::Custom(err) => f.write_str(err),
54 }
55 }
56}