1use core::fmt;
3
4pub type Result<T> = core::result::Result<T, Error>;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub enum Error {
13 Eof,
15 Interrupted,
17 OutputTooSmall,
19 WriteZero,
21 InvalidData,
23 InvalidHeader,
25 UnknownBlockType(u8),
29 InvalidParameter,
31 Other,
33}
34
35impl fmt::Display for Error {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 match self {
38 Self::Eof => f.write_str("unexpected end of input"),
39 Self::Interrupted => f.write_str("operation interrupted"),
40 Self::OutputTooSmall => f.write_str("output buffer too small"),
41 Self::WriteZero => f.write_str("failed to write data"),
42 Self::InvalidData => f.write_str("invalid compressed data"),
43 Self::InvalidHeader => f.write_str("invalid LZF block header"),
44 Self::UnknownBlockType(kind) => write!(f, "unknown LZF block type: {kind}"),
45 Self::InvalidParameter => f.write_str("invalid parameter"),
46 Self::Other => f.write_str("I/O error"),
47 }
48 }
49}
50
51#[cfg(feature = "std")]
52impl std::error::Error for Error {}
53
54#[cfg(feature = "std")]
55impl From<std::io::Error> for Error {
56 fn from(value: std::io::Error) -> Self {
57 match value.kind() {
58 std::io::ErrorKind::UnexpectedEof => Self::Eof,
59 std::io::ErrorKind::Interrupted => Self::Interrupted,
60 std::io::ErrorKind::InvalidData => Self::InvalidData,
61 std::io::ErrorKind::InvalidInput => Self::InvalidParameter,
62 std::io::ErrorKind::WriteZero => Self::WriteZero,
63 _ => Self::Other,
64 }
65 }
66}