compression/
error.rs

1//! rust-compression
2//!
3//! # Licensing
4//! This Source Code is subject to the terms of the Mozilla Public License
5//! version 2.0 (the "License"). You can obtain a copy of the License at
6//! <http://mozilla.org/MPL/2.0/>.
7
8use crate::core::fmt;
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum CompressionError {
12    DataError,
13    UnexpectedEof,
14    Unexpected,
15}
16
17impl fmt::Display for CompressionError {
18    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19        write!(f, "{}", self.description_in())
20    }
21}
22
23#[cfg(feature = "std")]
24impl ::std::error::Error for CompressionError {
25    fn description(&self) -> &str {
26        self.description_in()
27    }
28
29    fn cause(&self) -> Option<&dyn (::std::error::Error)> {
30        None
31    }
32}
33
34impl CompressionError {
35    fn description_in(&self) -> &str {
36        match *self {
37            CompressionError::DataError => "data integrity error in data",
38            CompressionError::UnexpectedEof => "file ends unexpectedly",
39            CompressionError::Unexpected => "unexpected error",
40        }
41    }
42}