1use std::error::Error;
4use std::fmt;
5
6use softbuffer::SoftBufferError;
7use winit::error::{EventLoopError, OsError};
8
9#[derive(Debug)]
12pub enum PlatformError {
13 EventLoop(EventLoopError),
15 Window(OsError),
17 Surface(SoftBufferError),
20 Renderer(String),
28 ClearColor,
33}
34
35impl fmt::Display for PlatformError {
36 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
37 match self {
38 PlatformError::EventLoop(error) => write!(formatter, "the event loop failed: {error}"),
39 PlatformError::Window(error) => {
40 write!(formatter, "the window could not be created: {error}")
41 }
42 PlatformError::Surface(error) => {
43 write!(formatter, "the presentation surface failed: {error}")
44 }
45 PlatformError::Renderer(message) => {
46 write!(formatter, "the renderer could not be set up: {message}")
47 }
48 PlatformError::ClearColor => write!(
49 formatter,
50 "the clear color must be opaque, because presentation drops \
51 the alpha channel of the surface"
52 ),
53 }
54 }
55}
56
57impl Error for PlatformError {
58 fn source(&self) -> Option<&(dyn Error + 'static)> {
59 match self {
60 PlatformError::EventLoop(error) => Some(error),
61 PlatformError::Window(error) => Some(error),
62 PlatformError::Surface(error) => Some(error),
63 PlatformError::Renderer(_) => None,
64 PlatformError::ClearColor => None,
65 }
66 }
67}