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
use std::io::Error as IOError;
use failure::Fail;
#[derive(Debug, Fail)]
pub enum Error {
#[fail(display = "Generation error: {}", _0)]
Generation(#[cause] GenerationError),
#[fail(display = "IO error: {}", _0)]
IO(#[cause] IOError),
}
#[derive(Debug, Fail)]
pub enum GenerationError {
#[fail(
display = "Unknown input format: `{}`. (Maybe you need to enable the right feature?)",
_0
)]
UnknownInputFormat(String),
#[fail(display = "Invalid field name: `{}`.", _0)]
InvalidFieldName(String),
#[fail(display = "Invalid variant name: `{}`.", _0)]
InvalidVariantName(String),
#[fail(
display = "Array under key `{}` has elements of different types. Arrays must be homogenous.",
_0
)]
HeterogenousArray(String),
#[fail(
display = "Cannot generate dynamic loading functions without a filename.
(Generate struct from a file, set generate_load_fns: false, or set dynamic_loading: DynamicLoading::Never to fix.)"
)]
MissingFilePath,
#[fail(display = "Deserialization failed: {}", _0)]
DeserializationFailed(String),
#[fail(display = "Invalid options error: {}", _0)]
StructOptions(#[cause] OptionsError),
}
#[derive(Debug, Fail)]
pub enum OptionsError {
#[fail(display = "Invalid name for a struct: `{}`.", _0)]
InvalidStructName(String),
#[fail(display = "Invalid name for a const: `{}`.", _0)]
InvalidConstName(String),
}
impl From<GenerationError> for Error {
fn from(error: GenerationError) -> Self {
Error::Generation(error)
}
}
impl From<IOError> for Error {
fn from(error: IOError) -> Self {
Error::IO(error)
}
}
impl From<OptionsError> for GenerationError {
fn from(error: OptionsError) -> Self {
GenerationError::StructOptions(error)
}
}