1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
use crate::WindowId;
#[derive(Debug)]
pub enum CreateWindowError {
Winit(winit::error::OsError),
GetDevice(GetDeviceError),
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ImageDataError {
UnsupportedImageFormat(UnsupportedImageFormat),
Other(String),
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct UnsupportedImageFormat {
pub format: String,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct InvalidWindowId {
pub window_id: WindowId,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum SetImageError {
InvalidWindowId(InvalidWindowId),
ImageDataError(ImageDataError),
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct UnknownOverlay {
pub name: String,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum GetDeviceError {
NoSuitableAdapterFound(NoSuitableAdapterFound),
NoSuitableDeviceFound(wgpu::RequestDeviceError),
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct NoSuitableAdapterFound;
#[derive(Debug)]
pub enum SaveImageError {
IoError(std::io::Error),
#[cfg(feature = "png")]
PngError(png::EncodingError),
}
impl From<winit::error::OsError> for CreateWindowError {
fn from(other: winit::error::OsError) -> Self {
Self::Winit(other)
}
}
impl From<GetDeviceError> for CreateWindowError {
fn from(other: GetDeviceError) -> Self {
Self::GetDevice(other)
}
}
impl From<ImageDataError> for SetImageError {
fn from(other: ImageDataError) -> Self {
Self::ImageDataError(other)
}
}
impl From<InvalidWindowId> for SetImageError {
fn from(other: InvalidWindowId) -> Self {
Self::InvalidWindowId(other)
}
}
impl From<UnsupportedImageFormat> for ImageDataError {
fn from(other: UnsupportedImageFormat) -> Self {
Self::UnsupportedImageFormat(other)
}
}
impl From<String> for ImageDataError {
fn from(other: String) -> Self {
Self::Other(other)
}
}
impl<'a> From<&'a str> for ImageDataError {
fn from(other: &'a str) -> Self {
Self::Other(other.to_string())
}
}
impl From<NoSuitableAdapterFound> for GetDeviceError {
fn from(other: NoSuitableAdapterFound) -> Self {
Self::NoSuitableAdapterFound(other)
}
}
impl From<wgpu::RequestDeviceError> for GetDeviceError {
fn from(other: wgpu::RequestDeviceError) -> Self {
Self::NoSuitableDeviceFound(other)
}
}
impl From<std::io::Error> for SaveImageError {
fn from(other: std::io::Error) -> Self {
Self::IoError(other)
}
}
#[cfg(feature = "png")]
impl From<png::EncodingError> for SaveImageError {
fn from(other: png::EncodingError) -> Self {
match other {
png::EncodingError::IoError(e) => Self::IoError(e),
e => Self::PngError(e),
}
}
}
impl std::error::Error for CreateWindowError {}
impl std::error::Error for ImageDataError {}
impl std::error::Error for UnsupportedImageFormat {}
impl std::error::Error for InvalidWindowId {}
impl std::error::Error for SetImageError {}
impl std::error::Error for UnknownOverlay {}
impl std::error::Error for GetDeviceError {}
impl std::error::Error for NoSuitableAdapterFound {}
impl std::error::Error for SaveImageError {}
impl std::fmt::Display for CreateWindowError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Winit(e) => write!(f, "{}", e),
Self::GetDevice(e) => write!(f, "{}", e),
}
}
}
impl std::fmt::Display for ImageDataError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::UnsupportedImageFormat(e) => write!(f, "{}", e),
Self::Other(e) => write!(f, "{}", e),
}
}
}
impl std::fmt::Display for UnsupportedImageFormat {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "unsupported image format: {}", self.format)
}
}
impl std::fmt::Display for InvalidWindowId {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "invalid window ID: {:?}", self.window_id)
}
}
impl std::fmt::Display for SetImageError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::InvalidWindowId(e) => write!(f, "{}", e),
Self::ImageDataError(e) => write!(f, "{}", e),
}
}
}
impl std::fmt::Display for UnknownOverlay {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "unknown overlay: {}", self.name)
}
}
impl std::fmt::Display for GetDeviceError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::NoSuitableAdapterFound(e) => write!(f, "{}", e),
Self::NoSuitableDeviceFound(e) => write!(f, "{}", e),
}
}
}
impl std::fmt::Display for NoSuitableAdapterFound {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "no suitable graphics adapter found")
}
}
impl std::fmt::Display for SaveImageError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::IoError(e) => write!(f, "{}", e),
#[cfg(feature = "png")]
Self::PngError(e) => write!(f, "{}", e),
}
}
}