bornera_core/framing/
error.rs1use core::fmt;
4
5use calandria::RetainedBytes;
6
7#[derive(Clone, Debug, Eq, PartialEq)]
9#[non_exhaustive]
10pub enum FrameDecodeError<E> {
11 DecoderFailed,
13 RetainedByteCapacity {
15 retained: RetainedBytes,
17 incoming: usize,
19 limit: RetainedBytes,
21 },
22 InputSizeOverflow,
24 Decoder(E),
26 RetainedContractViolation {
28 retained: RetainedBytes,
30 limit: RetainedBytes,
32 },
33}
34
35impl<E: fmt::Display> fmt::Display for FrameDecodeError<E> {
36 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
37 match self {
38 Self::DecoderFailed => formatter.write_str("the frame decoder has already failed"),
39 Self::RetainedByteCapacity { .. } => {
40 formatter.write_str("input would exceed decoder retained-byte capacity")
41 }
42 Self::InputSizeOverflow => {
43 formatter.write_str("input length exceeds the retained-byte accounting domain")
44 }
45 Self::Decoder(error) => error.fmt(formatter),
46 Self::RetainedContractViolation { .. } => {
47 formatter.write_str("decoder violated its retained-byte reporting contract")
48 }
49 }
50 }
51}
52
53impl<E: core::error::Error + 'static> core::error::Error for FrameDecodeError<E> {
54 fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
55 match self {
56 Self::Decoder(error) => Some(error),
57 _ => None,
58 }
59 }
60}