1use core::fmt;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum EncodeError {
6 BufferTooSmall,
7 ValueOutOfRange,
8 InvalidLength,
9 Unsupported,
10 Message(&'static str),
11}
12
13impl fmt::Display for EncodeError {
14 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15 match self {
16 Self::BufferTooSmall => f.write_str("buffer too small"),
17 Self::ValueOutOfRange => f.write_str("value out of range"),
18 Self::InvalidLength => f.write_str("invalid length"),
19 Self::Unsupported => f.write_str("operation unsupported"),
20 Self::Message(msg) => f.write_str(msg),
21 }
22 }
23}
24
25#[cfg(feature = "std")]
26impl std::error::Error for EncodeError {}
27
28#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30pub enum DecodeError {
31 UnexpectedEof,
32 InvalidTag,
33 InvalidLength,
34 InvalidValue,
35 Unsupported,
36 Message(&'static str),
37}
38
39impl fmt::Display for DecodeError {
40 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 match self {
42 Self::UnexpectedEof => f.write_str("unexpected end of input"),
43 Self::InvalidTag => f.write_str("invalid tag"),
44 Self::InvalidLength => f.write_str("invalid length"),
45 Self::InvalidValue => f.write_str("invalid value"),
46 Self::Unsupported => f.write_str("operation unsupported"),
47 Self::Message(msg) => f.write_str(msg),
48 }
49 }
50}
51
52#[cfg(feature = "std")]
53impl std::error::Error for DecodeError {}