1use std::{
4 fmt::{self, Display},
5 io,
6};
7
8#[non_exhaustive]
10#[derive(Debug)]
11pub enum MoshError {
12 DecodingError(png::DecodingError),
14 EncodingError(png::EncodingError),
16 IoError(io::Error),
18 OutOfMemory,
20 UnsupportedColorType,
22}
23
24impl std::error::Error for MoshError {}
25
26impl Display for MoshError {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 match self {
29 Self::DecodingError(e) => Display::fmt(e, f),
30 Self::EncodingError(e) => Display::fmt(e, f),
31 Self::IoError(e) => Display::fmt(e, f),
32 Self::OutOfMemory => f.write_str("Out of memory"),
33 Self::UnsupportedColorType => f.write_str("Unsupported color type"),
34 }
35 }
36}
37
38impl From<io::Error> for MoshError {
39 fn from(e: io::Error) -> Self {
40 Self::IoError(e)
41 }
42}
43
44impl From<png::DecodingError> for MoshError {
45 fn from(e: png::DecodingError) -> Self {
46 Self::DecodingError(e)
47 }
48}
49
50impl From<png::EncodingError> for MoshError {
51 fn from(e: png::EncodingError) -> Self {
52 Self::EncodingError(e)
53 }
54}