Skip to main content

weakauras_codec_lib_compress/
error.rs

1// Copyright 2025 Velithris
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4use core::fmt;
5use std::error;
6
7/// Errors than can occur while decompressing.
8#[derive(Clone, Debug, PartialEq, Eq)]
9#[non_exhaustive]
10pub enum DecompressionError {
11    /// Invalid prefix.
12    InvalidPrefix,
13    /// The input is too small.
14    InputIsTooSmall,
15    /// Compressed data exceeds provided maximum size.
16    DataExceedsMaxSize,
17    /// The input ended unexpectedly.
18    UnexpectedEof,
19    /// Catch-all variant for bogus input.
20    InvalidData,
21}
22
23impl fmt::Display for DecompressionError {
24    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25        match self {
26            Self::InvalidPrefix => write!(f, "Invalid prefix"),
27            Self::InputIsTooSmall => write!(f, "Input is too small"),
28            Self::DataExceedsMaxSize => write!(f, "Compressed data exceeds max size"),
29            Self::UnexpectedEof => write!(f, "Unexpected EOF"),
30            Self::InvalidData => write!(f, "Invalid data"),
31        }
32    }
33}
34
35impl error::Error for DecompressionError {}