1use std::{error, fmt};
2
3use crate::platform_impl;
4
5#[derive(Debug)]
7pub enum ExternalError {
8 NotSupported(NotSupportedError),
10 Os(OsError),
12}
13
14#[derive(Clone)]
16pub struct NotSupportedError {
17 _marker: (),
18}
19
20#[derive(Debug)]
22pub struct OsError {
23 line: u32,
24 file: &'static str,
25 error: platform_impl::OsError,
26}
27
28impl NotSupportedError {
29 #[inline]
30 #[allow(dead_code)]
31 pub(crate) fn new() -> NotSupportedError {
32 NotSupportedError { _marker: () }
33 }
34}
35
36impl OsError {
37 #[allow(dead_code)]
38 pub(crate) fn new(line: u32, file: &'static str, error: platform_impl::OsError) -> OsError {
39 OsError { line, file, error }
40 }
41}
42
43#[allow(unused_macros)]
44macro_rules! os_error {
45 ($error:expr) => {{
46 crate::error::OsError::new(line!(), file!(), $error)
47 }};
48}
49
50impl fmt::Display for OsError {
51 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
52 f.pad(&format!(
53 "os error at {}:{}: {}",
54 self.file, self.line, self.error
55 ))
56 }
57}
58
59impl fmt::Display for ExternalError {
60 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
61 match self {
62 ExternalError::NotSupported(e) => e.fmt(f),
63 ExternalError::Os(e) => e.fmt(f),
64 }
65 }
66}
67
68impl fmt::Debug for NotSupportedError {
69 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
70 f.debug_struct("NotSupportedError").finish()
71 }
72}
73
74impl fmt::Display for NotSupportedError {
75 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
76 f.pad("the requested operation is not supported by Winit")
77 }
78}
79
80impl error::Error for OsError {}
81impl error::Error for ExternalError {}
82impl error::Error for NotSupportedError {}