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