#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum DecodeError<SourceError, DestinationError> {
Source(SourceError),
Destination(DestinationError),
UnexpectedSourceEof,
EmptyFrame,
InvalidFrame(crate::DecodeProgress),
}
impl<S: core::error::Error, D: core::error::Error> core::error::Error for DecodeError<S, D> {}
impl<S, D> core::fmt::Display for DecodeError<S, D>
where
S: core::error::Error,
D: core::error::Error,
{
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
DecodeError::Source(e) => write!(f, "Source error: {}", e),
DecodeError::Destination(e) => write!(f, "Destination error: {}", e),
DecodeError::UnexpectedSourceEof => write!(f, "Unexpected source EOF"),
DecodeError::EmptyFrame => write!(f, "Empty frame"),
DecodeError::InvalidFrame(progress) => {
write!(f, "Invalid frame after decoding {:?}", progress)
}
}
}
}
#[cfg(feature = "defmt")]
impl<S, D> defmt::Format for DecodeError<S, D>
where
D: defmt::Format,
S: defmt::Format,
{
fn format(&self, f: defmt::Formatter<'_>) {
match self {
DecodeError::Source(e) => defmt::write!(f, "Source error: {}", e),
DecodeError::Destination(e) => defmt::write!(f, "Destination error: {}", e),
DecodeError::UnexpectedSourceEof => defmt::write!(f, "Unexpected source EOF"),
DecodeError::EmptyFrame => defmt::write!(f, "Empty frame"),
DecodeError::InvalidFrame(progress) => {
defmt::write!(f, "Invalid frame after decoding {:?}", progress)
}
}
}
}
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum SeekableError {
OutOfBounds,
}
impl core::error::Error for SeekableError {}
impl core::fmt::Display for SeekableError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
SeekableError::OutOfBounds => write!(f, "Out of bounds"),
}
}
}
#[cfg(feature = "defmt")]
impl defmt::Format for SeekableError {
fn format(&self, f: defmt::Formatter<'_>) {
match self {
SeekableError::OutOfBounds => defmt::write!(f, "Out of bounds"),
}
}
}
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum ConfigError {
BufferTooSmall,
}
impl core::error::Error for ConfigError {}
impl core::fmt::Display for ConfigError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
ConfigError::BufferTooSmall => write!(f, "Buffer cannot hold a protocol packet"),
}
}
}
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum ConnectionError<TransportError> {
Transport(TransportError),
UnexpectedEof,
WriteZero,
Timeout,
SequenceExhausted,
Failed,
}
impl<E: core::error::Error> core::error::Error for ConnectionError<E> {}
impl<E: core::fmt::Display> core::fmt::Display for ConnectionError<E> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
ConnectionError::Transport(e) => write!(f, "Transport error: {}", e),
ConnectionError::UnexpectedEof => write!(f, "Transport closed unexpectedly"),
ConnectionError::WriteZero => write!(f, "Transport accepted zero bytes"),
ConnectionError::Timeout => write!(f, "Retransmission attempts exhausted"),
ConnectionError::SequenceExhausted => write!(f, "Sequence numbers exhausted"),
ConnectionError::Failed => write!(f, "Connection previously failed"),
}
}
}