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
#[macro_use]
extern crate serde;
mod sys;
pub use crate::sys::*;
use std::fmt;
#[derive(Debug)]
pub enum Error {
InitError,
NulError(std::ffi::NulError),
#[cfg(target_os = "windows")]
WinrtError(winrt::Error),
#[cfg(not(target_os = "linux"))]
OsError(winit::error::OsError),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::InitError => "Fail to initialize instance".fmt(f),
Error::NulError(e) => e.fmt(f),
#[cfg(target_os = "windows")]
Error::WinrtError(e) => format!("{:?}", e).fmt(f),
#[cfg(not(target_os = "linux"))]
Error::OsError(e) => e.fmt(f),
}
}
}
impl std::error::Error for Error {}
#[cfg(target_os = "windows")]
impl From<winrt::Error> for Error {
fn from(error: winrt::Error) -> Self {
Error::WinrtError(error)
}
}
impl From<std::ffi::NulError> for Error {
fn from(error: std::ffi::NulError) -> Self {
Error::NulError(error)
}
}