1use core::fmt;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5#[cfg_attr(feature = "defmt", derive(defmt::Format))]
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7#[non_exhaustive]
8pub enum EncodeError {
9 BufferTooSmall,
11 ValueOutOfRange,
13 InvalidLength,
15 Unsupported,
17 Message(&'static str),
19}
20
21impl fmt::Display for EncodeError {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 match self {
24 Self::BufferTooSmall => f.write_str("buffer too small"),
25 Self::ValueOutOfRange => f.write_str("value out of range"),
26 Self::InvalidLength => f.write_str("invalid length"),
27 Self::Unsupported => f.write_str("operation unsupported"),
28 Self::Message(msg) => f.write_str(msg),
29 }
30 }
31}
32
33#[cfg(feature = "std")]
34impl std::error::Error for EncodeError {}
35
36#[derive(Debug, Clone, Copy, PartialEq, Eq)]
38#[cfg_attr(feature = "defmt", derive(defmt::Format))]
39#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
40#[non_exhaustive]
41pub enum DecodeError {
42 UnexpectedEof,
44 InvalidFunctionCode,
46 InvalidLength,
48 InvalidValue,
50 InvalidCrc,
52 Unsupported,
54 Message(&'static str),
56}
57
58impl fmt::Display for DecodeError {
59 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60 match self {
61 Self::UnexpectedEof => f.write_str("unexpected end of input"),
62 Self::InvalidFunctionCode => f.write_str("invalid function code"),
63 Self::InvalidLength => f.write_str("invalid length"),
64 Self::InvalidValue => f.write_str("invalid value"),
65 Self::InvalidCrc => f.write_str("invalid crc"),
66 Self::Unsupported => f.write_str("operation unsupported"),
67 Self::Message(msg) => f.write_str(msg),
68 }
69 }
70}
71
72#[cfg(feature = "std")]
73impl std::error::Error for DecodeError {}