devela/media/image/
error.rs
1#[cfg(any(feature = "std", all(not(feature = "std"), feature = "io")))]
8use crate::IoErrorKind;
9
10#[doc = crate::TAG_RESULT!()]
11pub type ImageResult<T> = crate::Result<T, ImageError>;
13
14#[doc = crate::TAG_ERROR_COMPOSITE!()]
15#[derive(Clone, Copy, Debug, PartialEq, Eq)]
17pub enum ImageError {
18 InvalidImageSize(Option<(usize, usize)>), InvalidPixel, InvalidMagicNumber,
27
28 InvalidParsedInteger,
33
34 FmtError,
36
37 #[cfg(any(feature = "std", all(not(feature = "std"), feature = "io")))]
39 #[cfg_attr(
40 feature = "nightly_doc",
41 doc(cfg(any(feature = "std", all(not(feature = "std"), feature = "io"))))
42 )]
43 IoError(IoErrorKind),
44}
45
46mod core_impls {
47 #[cfg(any(feature = "std", all(not(feature = "std"), feature = "io")))]
48 use crate::IoError;
49 use crate::{Display, FmtResult, Formatter, ImageError};
50 use core::fmt;
51
52 impl crate::Error for ImageError {}
53 impl crate::ExtError for ImageError {
54 type Kind = ();
55 fn error_eq(&self, other: &Self) -> bool {
56 self == other
57 }
58 fn error_kind(&self) -> Self::Kind {}
59 }
60
61 impl Display for ImageError {
62 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult<()> {
63 use ImageError as E;
64 match self {
65 E::InvalidImageSize(o) => write!(f, "InvalidImageSize: {o:?}"),
66 E::InvalidMagicNumber => write!(f, "Invalid magic number."),
67 E::InvalidPixel => write!(f, "Invalid pixel."),
68 E::InvalidParsedInteger => write!(f, "Invalid parsed integer."),
71 E::FmtError => write!(f, "A core::fmt::Error."),
72 #[cfg(any(feature = "std", all(not(feature = "std"), feature = "io")))]
73 E::IoError(e) => write!(f, "An I/O Error: {e:?}"),
74 }
75 }
76 }
77
78 impl From<crate::ParseIntError> for ImageError {
80 fn from(_: crate::ParseIntError) -> Self {
81 Self::InvalidParsedInteger
83 }
84 }
85 impl From<fmt::Error> for ImageError {
87 fn from(_: fmt::Error) -> Self {
88 Self::FmtError
89 }
90 }
91 #[cfg(any(feature = "std", all(not(feature = "std"), feature = "io")))]
92 impl From<IoError> for ImageError {
93 fn from(e: IoError) -> Self {
94 Self::IoError(e.kind())
95 }
96 }
97}