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
109
110
111
112
macro_rules! try_vec {
($elem:expr; $size:expr) => {{
let mut v = Vec::new();
v.try_reserve_exact($size)?;
v.resize($size, $elem);
v
}};
}
macro_rules! err {
($variant:ident) => {
return Err(crate::error::LoftyError::new(
crate::error::ErrorKind::$variant,
))
};
($variant:ident($reason:literal)) => {
return Err(crate::error::LoftyError::new(
crate::error::ErrorKind::$variant($reason),
))
};
}
macro_rules! decode_err {
($file_ty:ident, $reason:literal) => {
Into::<crate::error::LoftyError>::into(crate::error::FileDecodingError::new(
crate::file::FileType::$file_ty,
$reason,
))
};
($reason:literal) => {
Into::<crate::error::LoftyError>::into(crate::error::FileDecodingError::from_description(
$reason,
))
};
(@BAIL $($file_ty:ident,)? $reason:literal) => {
return Err(decode_err!($($file_ty,)? $reason))
};
}
macro_rules! parse_mode_choice {
(
$parse_mode:ident,
$(STRICT: $strict_handler:expr,)?
$(RELAXED: $relaxed_handler:expr,)?
DEFAULT: $default:expr
) => {
match $parse_mode {
$(crate::probe::ParsingMode::Strict => { $strict_handler },)?
$(crate::probe::ParsingMode::Relaxed => { $relaxed_handler },)?
_ => { $default }
}
};
(
$parse_mode:ident,
$(STRICT: $strict_handler:expr,)?
$(RELAXED: $relaxed_handler:expr $(,)?)?
) => {
match $parse_mode {
$(crate::probe::ParsingMode::Strict => { $strict_handler },)?
$(crate::probe::ParsingMode::Relaxed => { $relaxed_handler },)?
#[allow(unreachable_patterns)]
_ => { unreachable!() }
}
};
}
pub(crate) use {decode_err, err, parse_mode_choice, try_vec};