1use std::fmt;
6use std::io;
7use std::num::TryFromIntError;
8
9#[derive(Debug)]
11pub enum Error {
12 Io(io::Error),
14 TryFromInt(TryFromIntError),
16 MalformedHeader,
18 UnsupportedVersion([u8; 3]),
20 InvalidBlockCode,
22 InvalidBlockSequence,
24 MalformedGraphicControlExtension,
27 UnexpectedEndOfFile,
29 InvalidLzwData,
31 TooLargeImage,
34 IncompleteImageData,
36 InvalidFrameDimensions,
38 MissingColorTable,
40 InvalidColorIndex,
42 InvalidRasterDimensions,
44}
45
46pub type Result<T> = std::result::Result<T, Error>;
48
49impl fmt::Display for Error {
50 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
51 match self {
52 Error::Io(err) => err.fmt(fmt),
53 Error::TryFromInt(err) => err.fmt(fmt),
54 _ => fmt::Debug::fmt(self, fmt),
55 }
56 }
57}
58
59impl std::error::Error for Error {
60 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
61 match *self {
62 Error::Io(ref err) => Some(err),
63 Error::TryFromInt(ref err) => Some(err),
64 _ => None,
65 }
66 }
67}
68
69impl From<io::Error> for Error {
70 fn from(err: io::Error) -> Self {
71 Error::Io(err)
72 }
73}
74
75impl From<TryFromIntError> for Error {
76 fn from(err: TryFromIntError) -> Self {
77 Error::TryFromInt(err)
78 }
79}