1#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
15#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16pub enum DecodeError<SourceError, DestinationError> {
17 Source(SourceError),
22
23 Destination(DestinationError),
29
30 UnexpectedSourceEof,
32
33 EmptyFrame,
38
39 InvalidFrame(crate::DecodeProgress),
46}
47
48impl<S: core::error::Error, D: core::error::Error> core::error::Error for DecodeError<S, D> {}
49
50impl<S, D> core::fmt::Display for DecodeError<S, D>
51where
52 S: core::error::Error,
53 D: core::error::Error,
54{
55 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
56 match self {
57 DecodeError::Source(e) => write!(f, "Source error: {}", e),
58 DecodeError::Destination(e) => write!(f, "Destination error: {}", e),
59 DecodeError::UnexpectedSourceEof => write!(f, "Unexpected source EOF"),
60 DecodeError::EmptyFrame => write!(f, "Empty frame"),
61 DecodeError::InvalidFrame(progress) => {
62 write!(f, "Invalid frame after decoding {:?}", progress)
63 }
64 }
65 }
66}
67
68#[cfg(feature = "defmt")]
69impl<S, D> defmt::Format for DecodeError<S, D>
70where
71 D: defmt::Format,
72 S: defmt::Format,
73{
74 fn format(&self, f: defmt::Formatter<'_>) {
75 match self {
76 DecodeError::Source(e) => defmt::write!(f, "Source error: {}", e),
77 DecodeError::Destination(e) => defmt::write!(f, "Destination error: {}", e),
78 DecodeError::UnexpectedSourceEof => defmt::write!(f, "Unexpected source EOF"),
79 DecodeError::EmptyFrame => defmt::write!(f, "Empty frame"),
80 DecodeError::InvalidFrame(progress) => {
81 defmt::write!(f, "Invalid frame after decoding {:?}", progress)
82 }
83 }
84 }
85}
86
87#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
94#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
95pub enum SeekableError {
96 OutOfBounds,
99}
100
101impl core::error::Error for SeekableError {}
102impl core::fmt::Display for SeekableError {
103 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
104 match self {
105 SeekableError::OutOfBounds => write!(f, "Out of bounds"),
106 }
107 }
108}
109
110#[cfg(feature = "defmt")]
111impl defmt::Format for SeekableError {
112 fn format(&self, f: defmt::Formatter<'_>) {
113 match self {
114 SeekableError::OutOfBounds => defmt::write!(f, "Out of bounds"),
115 }
116 }
117}
118
119#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
120#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
121#[cfg_attr(feature = "defmt", derive(defmt::Format))]
122pub enum ConfigError {
125 BufferTooSmall,
130}
131
132impl core::error::Error for ConfigError {}
133
134impl core::fmt::Display for ConfigError {
135 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
136 match self {
137 ConfigError::BufferTooSmall => write!(f, "Buffer cannot hold a protocol packet"),
138 }
139 }
140}
141
142#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
143#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
144#[cfg_attr(feature = "defmt", derive(defmt::Format))]
145pub enum ConnectionError<TransportError> {
151 Transport(TransportError),
153
154 UnexpectedEof,
156
157 WriteZero,
159
160 Timeout,
163
164 SequenceExhausted,
168
169 Failed,
172}
173
174impl<E: core::error::Error> core::error::Error for ConnectionError<E> {}
175
176impl<E: core::fmt::Display> core::fmt::Display for ConnectionError<E> {
177 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
178 match self {
179 ConnectionError::Transport(e) => write!(f, "Transport error: {}", e),
180 ConnectionError::UnexpectedEof => write!(f, "Transport closed unexpectedly"),
181 ConnectionError::WriteZero => write!(f, "Transport accepted zero bytes"),
182 ConnectionError::Timeout => write!(f, "Retransmission attempts exhausted"),
183 ConnectionError::SequenceExhausted => write!(f, "Sequence numbers exhausted"),
184 ConnectionError::Failed => write!(f, "Connection previously failed"),
185 }
186 }
187}