1#[derive(Debug)]
2#[non_exhaustive]
3pub enum Error {
4 Bitstream(jxl_bitstream::Error),
5 Decoder(jxl_coding::Error),
6 Buffer(jxl_grid::Error),
7 Modular(jxl_modular::Error),
8}
9
10impl From<jxl_bitstream::Error> for Error {
11 fn from(err: jxl_bitstream::Error) -> Self {
12 Self::Bitstream(err)
13 }
14}
15
16impl From<jxl_coding::Error> for Error {
17 fn from(err: jxl_coding::Error) -> Self {
18 Self::Decoder(err)
19 }
20}
21
22impl From<jxl_grid::Error> for Error {
23 fn from(err: jxl_grid::Error) -> Self {
24 Self::Buffer(err)
25 }
26}
27
28impl From<jxl_modular::Error> for Error {
29 fn from(err: jxl_modular::Error) -> Self {
30 Self::Modular(err)
31 }
32}
33
34impl std::fmt::Display for Error {
35 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36 use Error::*;
37
38 match self {
39 Bitstream(err) => write!(f, "bitstream error: {}", err),
40 Decoder(err) => write!(f, "entropy decoder error: {}", err),
41 Buffer(err) => write!(f, "{}", err),
42 Modular(err) => write!(f, "modular stream error: {}", err),
43 }
44 }
45}
46
47impl std::error::Error for Error {
48 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
49 use Error::*;
50
51 match self {
52 Bitstream(err) => Some(err),
53 Decoder(err) => Some(err),
54 Buffer(err) => Some(err),
55 Modular(err) => Some(err),
56 }
57 }
58}
59
60impl Error {
61 pub fn unexpected_eof(&self) -> bool {
62 match self {
63 Error::Bitstream(e) => e.unexpected_eof(),
64 Error::Decoder(e) => e.unexpected_eof(),
65 Error::Modular(e) => e.unexpected_eof(),
66 _ => false,
67 }
68 }
69}
70
71pub type Result<T> = std::result::Result<T, Error>;