1use std::{
2 error,
3 fmt::{self, Display, Formatter},
4};
5
6#[derive(Debug)]
9pub enum Error {
10 InvalidTextureSize {
13 width: u32,
15 height: u32,
17 },
18 ImageError(image::ImageError),
20 CreationError(glutin::CreationError),
22 ContextError(glutin::ContextError),
25}
26
27impl Display for Error {
28 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
29 match self {
30 Self::InvalidTextureSize { width, height } => write!(
31 f,
32 "failed to create a texture of the given size: {}x{}",
33 width, height
34 ),
35 Self::ImageError(err) => write!(f, "{}", err),
36 Self::CreationError(err) => write!(f, "{}", err),
37 Self::ContextError(err) => write!(f, "{}", err),
38 }
39 }
40}
41
42impl error::Error for Error {}
43
44#[derive(Debug)]
45pub enum NewContextError {
47 CreationError(glutin::CreationError),
49 ContextError(glutin::ContextError),
51}
52
53impl Display for NewContextError {
54 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
55 match self {
56 Self::CreationError(err) => write!(f, "{}", err),
57 Self::ContextError(err) => write!(f, "{}", err),
58 }
59 }
60}
61
62impl error::Error for NewContextError {}
63
64impl From<NewContextError> for Error {
65 fn from(e: NewContextError) -> Self {
66 match e {
67 NewContextError::CreationError(e) => Error::CreationError(e),
68 NewContextError::ContextError(e) => Error::ContextError(e),
69 }
70 }
71}
72
73#[derive(Debug)]
75pub enum FinalizeError {
76 ContextError(glutin::ContextError),
78}
79
80impl Display for FinalizeError {
81 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
82 match self {
83 Self::ContextError(err) => write!(f, "{}", err),
84 }
85 }
86}
87
88impl error::Error for FinalizeError {}
89
90impl From<FinalizeError> for Error {
91 fn from(e: FinalizeError) -> Self {
92 match e {
93 FinalizeError::ContextError(e) => Error::ContextError(e),
94 }
95 }
96}
97
98#[derive(Debug)]
100pub enum LoadTextureError {
101 InvalidTextureSize {
104 width: u32,
106 height: u32,
108 },
109 ImageError(image::ImageError),
111}
112
113impl Display for LoadTextureError {
114 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
115 match self {
116 Self::InvalidTextureSize { width, height } => write!(
117 f,
118 "failed to create a texture of the given size: {}x{}",
119 width, height
120 ),
121 Self::ImageError(err) => write!(f, "{}", err),
122 }
123 }
124}
125
126impl error::Error for LoadTextureError {}
127
128impl From<LoadTextureError> for Error {
129 fn from(e: LoadTextureError) -> Self {
130 match e {
131 LoadTextureError::InvalidTextureSize { width, height } => {
132 Error::InvalidTextureSize { width, height }
133 }
134 LoadTextureError::ImageError(e) => Error::ImageError(e),
135 }
136 }
137}
138
139#[derive(Debug)]
141pub enum NewTextureError {
142 InvalidTextureSize {
145 width: u32,
147 height: u32,
149 },
150}
151
152impl Display for NewTextureError {
153 fn fmt<'a>(&'a self, f: &mut Formatter<'_>) -> fmt::Result {
154 match self {
155 Self::InvalidTextureSize { width, height } => write!(
156 f,
157 "failed to create a texture of the given size: {}x{}",
158 width, height
159 ),
160 }
161 }
162}
163
164impl error::Error for NewTextureError {}
165
166impl From<NewTextureError> for LoadTextureError {
167 fn from(e: NewTextureError) -> Self {
168 match e {
169 NewTextureError::InvalidTextureSize { width, height } => {
170 LoadTextureError::InvalidTextureSize { width, height }
171 }
172 }
173 }
174}
175
176impl From<NewTextureError> for Error {
177 fn from(e: NewTextureError) -> Self {
178 match e {
179 NewTextureError::InvalidTextureSize { width, height } => {
180 Error::InvalidTextureSize { width, height }
181 }
182 }
183 }
184}