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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
use std::error::Error;
use std::fmt;
use std::io;
use std::env;
use super::sheet::SheetError;
use super::position::PostureError;
use super::emotion::EmotionError;
use super::sprite::draw::DrawError;
use super::sprite::texel::TexelError;
use super::sprite::texel::part::PartError;
pub type Result<T> = ::std::result::Result<T, GraphicError>;
#[derive(Debug)]
pub enum GraphicError {
ReadDir(io::Error),
OpenFile(io::Error),
ReadFile(io::Error),
MkDirTexel(io::Error),
MkDirSprite(io::Error),
Posture(PostureError),
Draw(DrawError),
Emotion(EmotionError),
Texel(TexelError),
SpriteSplitFirst(String),
Part(PartError),
Sheet(SheetError),
NekoPath,
Glyph,
FoundTexel(String),
SyntaxTexel(String),
}
impl fmt::Display for GraphicError {
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
Ok(())
}
}
impl Error for GraphicError {
fn description(&self) -> &str {
match *self {
GraphicError::ReadDir(_) => "Can't read the sub-directory.",
GraphicError::OpenFile(_) => "Can't open the file.",
GraphicError::ReadFile(_) => "Can't read the file.",
GraphicError::MkDirTexel(_) => "Can't create the texel sub-directory.",
GraphicError::MkDirSprite(_) => "Can't create the sprite sub-directory.",
GraphicError::Posture(_) => "The Posture interface has meet an error.",
GraphicError::Draw(_) => "The Draw interface has meet an error.",
GraphicError::Emotion(_) => "The Emotion interface has meet an error.",
GraphicError::Texel(_) => "The Texel interface has meet an error.",
GraphicError::Part(_) => "The Part interface has meet an error.",
GraphicError::Sheet(_) => "The Sheet interface has meet an error.",
GraphicError::NekoPath => "Can't found the $NEKO_PATH environement variable.",
GraphicError::Glyph => "Can't found the glyph of texel.",
GraphicError::SpriteSplitFirst(ref name) => name,
GraphicError::FoundTexel(ref name) => name,
GraphicError::SyntaxTexel(ref name) => name,
}
}
fn cause(&self) -> Option<&Error> {
match *self {
GraphicError::ReadDir(ref why) |
GraphicError::OpenFile(ref why) |
GraphicError::ReadFile(ref why) |
GraphicError::MkDirTexel(ref why) |
GraphicError::MkDirSprite(ref why) => Some(why),
GraphicError::Posture(ref why) => Some(why),
GraphicError::Draw(ref why) => Some(why),
GraphicError::Emotion(ref why) => Some(why),
GraphicError::Texel(ref why) => Some(why),
GraphicError::Part(ref why) => Some(why),
_ => None,
}
}
}
impl From<env::VarError> for GraphicError {
fn from(_: env::VarError) -> GraphicError {
GraphicError::NekoPath
}
}