diff options
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..8c2f096 --- /dev/null +++ b/src/error.rs | |||
@@ -0,0 +1,45 @@ | |||
1 | use std::{error, fmt}; | ||
2 | |||
3 | pub type OBIResult<T> = Result<T, OBIError>; | ||
4 | |||
5 | #[derive(Debug)] | ||
6 | pub enum OBIError { | ||
7 | Encode, | ||
8 | Decode, | ||
9 | Image, | ||
10 | } | ||
11 | |||
12 | impl fmt::Display for OBIError { | ||
13 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
14 | match self { | ||
15 | OBIError::Encode => writeln!(f, "Encoding error"), | ||
16 | OBIError::Decode => writeln!(f, "Decoding error"), | ||
17 | OBIError::Image => writeln!(f, "Image manipulation error"), | ||
18 | } | ||
19 | } | ||
20 | } | ||
21 | |||
22 | impl error::Error for OBIError {} | ||
23 | |||
24 | #[derive(Debug)] | ||
25 | enum Encode { | ||
26 | Metadata(MetadataError), | ||
27 | ChunkError(u32), | ||
28 | } | ||
29 | |||
30 | #[derive(Debug)] | ||
31 | enum Decode { | ||
32 | Metadata(MetadataError), | ||
33 | ChunkError(u32), | ||
34 | } | ||
35 | |||
36 | #[derive(Debug)] | ||
37 | enum MetadataError { | ||
38 | VersionError, | ||
39 | FileSizeError, | ||
40 | DataOffsetError, | ||
41 | WidthError, | ||
42 | HeightError, | ||
43 | CompressionTypeError, | ||
44 | PostCompressionSizeError, | ||
45 | } | ||