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
#![allow(dead_code)]
use std::fmt;
#[derive(Debug)]
pub enum Error {
CannotCreateWindow(String),
CannotCreateStore(String),
DemoInitializationFailure(String),
}
impl Error {
pub fn cannot_create_window<R>(reason: R) -> Self
where
R: Into<String>,
{
Error::CannotCreateWindow(reason.into())
}
pub fn cannot_create_store<R>(reason: R) -> Self
where
R: Into<String>,
{
Error::CannotCreateStore(reason.into())
}
pub fn app_initialization_failure<R>(reason: R) -> Self
where
R: Into<String>,
{
Error::DemoInitializationFailure(reason.into())
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match *self {
Error::CannotCreateWindow(ref reason) => write!(f, "cannot create window: {}", reason),
Error::CannotCreateStore(ref reason) => write!(f, "cannot create store: {}", reason),
Error::DemoInitializationFailure(ref reason) => {
write!(f, "app failed to initialize: {}", reason)
}
}
}
}