1use core::fmt;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8#[non_exhaustive]
9pub enum Error {
10 UnknownFrame,
12 Truncated,
14 Corrupted,
16 ChecksumMismatch,
18 UnsupportedFrameParameter,
20 WindowTooLarge,
22 DictionaryMismatch,
24 InvalidDictionary,
26 OutputTooSmall,
28 OutputTooLarge,
30 SrcSizeWrong,
33 StageWrong,
36 MemoryAllocation,
41}
42
43impl fmt::Display for Error {
44 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45 f.write_str(match self {
46 Error::UnknownFrame => "unknown frame magic number (not zstd data)",
47 Error::Truncated => "compressed data is truncated",
48 Error::Corrupted => "compressed data is corrupt",
49 Error::ChecksumMismatch => "content checksum mismatch",
50 Error::UnsupportedFrameParameter => "unsupported frame parameter",
51 Error::WindowTooLarge => "frame window is larger than the decoder limit",
52 Error::DictionaryMismatch => "frame requires a different dictionary",
53 Error::InvalidDictionary => "invalid dictionary",
54 Error::OutputTooSmall => "output buffer is too small",
55 Error::OutputTooLarge => "decompressed size is too large",
56 Error::SrcSizeWrong => "input size differs from the pledged source size",
57 Error::StageWrong => "operation not possible at this stage of the stream",
58 Error::MemoryAllocation => "not enough memory for the compression parameters",
59 })
60 }
61}
62
63impl core::error::Error for Error {}
64
65#[cfg(feature = "std")]
66impl From<Error> for std::io::Error {
67 fn from(e: Error) -> Self {
68 let kind = match e {
69 Error::Truncated => std::io::ErrorKind::UnexpectedEof,
70 Error::MemoryAllocation => std::io::ErrorKind::OutOfMemory,
71 _ => std::io::ErrorKind::InvalidData,
72 };
73 std::io::Error::new(kind, e)
74 }
75}
76
77pub(crate) type Result<T> = core::result::Result<T, Error>;