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
use std::fmt;
use std::sync::Arc;
use crate::backend::error as backend;
#[derive(Debug, Clone)]
pub enum Error {
ApplicationAlreadyExists,
WindowDropped,
Platform(backend::Error),
Other(Arc<anyhow::Error>),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match self {
Error::ApplicationAlreadyExists => {
write!(f, "An application instance has already been created.")
}
Error::Platform(err) => fmt::Display::fmt(err, f),
Error::WindowDropped => write!(f, "The window has already been destroyed."),
Error::Other(s) => write!(f, "{}", s),
}
}
}
impl std::error::Error for Error {}
impl From<anyhow::Error> for Error {
fn from(src: anyhow::Error) -> Error {
Error::Other(Arc::new(src))
}
}
impl From<backend::Error> for Error {
fn from(src: backend::Error) -> Error {
Error::Platform(src)
}
}