1 | use std::{ |
2 | error::Error, |
3 | ffi::NulError, |
4 | fmt::{self, Display, Formatter}, |
5 | io, |
6 | }; |
7 | |
8 | /// Enum with all possible canvas errors that could occur. |
9 | #[derive (Debug)] |
10 | #[non_exhaustive ] |
11 | pub enum ErrorKind { |
12 | UnknownError, |
13 | GeneralError(String), |
14 | #[cfg (feature = "image-loading" )] |
15 | ImageError(::image::ImageError), |
16 | IoError(io::Error), |
17 | FontParseError, |
18 | NoFontFound, |
19 | FontInfoExtractionError, |
20 | FontSizeTooLargeForAtlas, |
21 | ShaderCompileError(String), |
22 | ShaderLinkError(String), |
23 | RenderTargetError(String), |
24 | ImageIdNotFound, |
25 | ImageUpdateOutOfBounds, |
26 | ImageUpdateWithDifferentFormat, |
27 | UnsupportedImageFormat, |
28 | } |
29 | |
30 | impl Display for ErrorKind { |
31 | fn fmt(&self, f: &mut Formatter) -> fmt::Result { |
32 | write!(f, "canvas error" ) |
33 | } |
34 | } |
35 | |
36 | #[cfg (feature = "image-loading" )] |
37 | impl From<::image::ImageError> for ErrorKind { |
38 | fn from(error: ::image::ImageError) -> Self { |
39 | Self::ImageError(error) |
40 | } |
41 | } |
42 | |
43 | impl From<io::Error> for ErrorKind { |
44 | fn from(error: io::Error) -> Self { |
45 | Self::IoError(error) |
46 | } |
47 | } |
48 | |
49 | impl From<NulError> for ErrorKind { |
50 | fn from(error: NulError) -> Self { |
51 | Self::GeneralError(error.to_string()) |
52 | } |
53 | } |
54 | |
55 | impl Error for ErrorKind {} |
56 | |