1use std::fmt;
2use std::io::Error as IoError;
3
4pub type Result<T, E = Error> = ::std::result::Result<T, E>;
5
6#[derive(Debug)]
8pub enum Error {
9 Format(&'static str),
12 Unsupported,
14 Io(IoError),
16}
17
18impl fmt::Display for Error {
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20 match *self {
21 Self::Format(desc) => f.write_str(desc),
22 Self::Unsupported => f.write_str("unsupported JPEG feature"),
23 Self::Io(ref err) => err.fmt(f),
24 }
25 }
26}
27
28#[cfg(not(target_arch = "wasm32"))]
29impl std::error::Error for Error {
30 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
31 match *self {
32 Self::Io(ref err) => Some(err),
33 _ => None,
34 }
35 }
36}
37
38impl From<IoError> for Error {
39 fn from(err: IoError) -> Self {
40 Self::Io(err)
41 }
42}