vg/
error.rs

1use std::error::Error;
2use std::ffi::NulError;
3use std::fmt::{
4    self,
5    Display,
6    Formatter,
7};
8use std::io;
9
10/// Enum with all possible canvas errors that could occur.
11#[derive(Debug)]
12#[non_exhaustive]
13pub enum ErrorKind {
14    /// Unknown error
15    UnknownError,
16    /// General error
17    GeneralError(String),
18    /// Image error
19    #[cfg(feature = "image-loading")]
20    ImageError(::image::ImageError),
21    /// IO error
22    IoError(io::Error),
23    /// Font parse error
24    FontParseError,
25    /// Not found error
26    NoFontFound,
27    /// Font info extraction error
28    FontInfoExtracionError,
29    /// Font size too large for atlas error
30    FontSizeTooLargeForAtlas,
31    /// Shader compile error
32    ShaderCompileError(String),
33    /// Shader link error
34    ShaderLinkError(String),
35    /// Render target error
36    RenderTargetError(String),
37    /// Image Id not found error
38    ImageIdNotFound,
39    /// Image update out of bounds error
40    ImageUpdateOutOfBounds,
41    /// Image update with different format error
42    ImageUpdateWithDifferentFormat,
43    /// Unsuported image format error
44    UnsuportedImageFromat,
45}
46
47impl Display for ErrorKind {
48    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
49        write!(f, "canvas error")
50    }
51}
52
53#[cfg(feature = "image-loading")]
54impl From<::image::ImageError> for ErrorKind {
55    fn from(error: ::image::ImageError) -> Self {
56        Self::ImageError(error)
57    }
58}
59
60impl From<io::Error> for ErrorKind {
61    fn from(error: io::Error) -> Self {
62        Self::IoError(error)
63    }
64}
65
66impl From<NulError> for ErrorKind {
67    fn from(error: NulError) -> Self {
68        Self::GeneralError(error.to_string())
69    }
70}
71
72impl Error for ErrorKind {}