cloudflare_soos/
error.rs

1use std::fmt;
2use std::io::Error as IoError;
3
4pub type Result<T, E = Error> = ::std::result::Result<T, E>;
5
6/// Errors that can occur while decoding a JPEG image.
7#[derive(Debug)]
8pub enum Error {
9    /// The image is not formatted properly. The string contains detailed information about the
10    /// error.
11    Format(&'static str),
12    /// The image makes use of a JPEG feature not (currently) supported by this library.
13    Unsupported,
14    /// An I/O error occurred while decoding the image.
15    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}