1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use std::{convert, error, fmt, io, result};
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ErrorKind {
InitializationFailed,
CompressionFailed,
DecompressionFailed,
FrameHeaderInvalid,
CompressedDataIncomplete,
DictionaryChangedDuringDecompression,
}
impl fmt::Display for ErrorKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> {
<Self as fmt::Debug>::fmt(self, f)
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Error {
kind: ErrorKind,
}
impl Error {
pub(crate) const fn new(kind: ErrorKind) -> Self {
Self { kind }
}
pub const fn kind(self) -> ErrorKind {
self.kind
}
}
impl convert::From<Error> for io::Error {
fn from(err: Error) -> Self {
Self::new(io::ErrorKind::Other, err)
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> {
<ErrorKind as fmt::Display>::fmt(&self.kind, f)
}
}
impl error::Error for Error {}
pub type Result<T> = result::Result<T, Error>;