1use alloc::string::String;
5use alloc::vec;
6use alloc::vec::Vec;
7use core::fmt::{Debug, Display, Formatter};
8
9pub struct InflateDecodeErrors
20{
21 pub error: DecodeErrorStatus,
23 pub data: Vec<u8>
25}
26
27impl InflateDecodeErrors
28{
29 pub fn new(error: DecodeErrorStatus, data: Vec<u8>) -> InflateDecodeErrors
39 {
40 InflateDecodeErrors { error, data }
41 }
42 pub fn new_with_error(error: DecodeErrorStatus) -> InflateDecodeErrors
47 {
48 InflateDecodeErrors::new(error, vec![])
49 }
50}
51
52impl Debug for InflateDecodeErrors
53{
54 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result
55 {
56 writeln!(f, "{:?}", self.error)
57 }
58}
59
60pub enum DecodeErrorStatus
61{
62 InsufficientData,
65 Generic(&'static str),
67 GenericStr(String),
70 CorruptData,
72 OutputLimitExceeded(usize, usize),
75 MismatchedCRC(u32, u32),
79 MismatchedAdler(u32, u32)
83}
84
85impl Debug for DecodeErrorStatus
86{
87 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result
88 {
89 match self
90 {
91 Self::InsufficientData => writeln!(f, "Insufficient data"),
92 Self::Generic(reason) => writeln!(f, "{reason}"),
93 Self::GenericStr(reason) => writeln!(f, "{reason}"),
94 Self::CorruptData => writeln!(f, "Corrupt data"),
95 Self::OutputLimitExceeded(limit, current) => writeln!(
96 f,
97 "Output limit exceeded, set limit was {limit} and output size is {current}"
98 ),
99 Self::MismatchedCRC(expected, found) =>
100 {
101 writeln!(f, "Mismatched CRC, expected {expected} but found {found}")
102 }
103 Self::MismatchedAdler(expected, found) =>
104 {
105 writeln!(f, "Mismatched Adler, expected {expected} but found {found}")
106 }
107 }
108 }
109}
110
111impl Display for InflateDecodeErrors
112{
113 #[allow(clippy::uninlined_format_args)]
114 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result
115 {
116 writeln!(f, "{:?}", self)
117 }
118}
119
120#[cfg(feature = "std")]
121impl std::error::Error for InflateDecodeErrors {}