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
use crate::amount::ConversionError;
#[derive(Debug, Clone)]
pub struct Error(Content);
impl Error {
pub(crate) fn from_conversion(err: ConversionError) -> Self {
Self(Content::ConversionError(err))
}
#[cfg(feature = "unstable")]
pub(crate) fn from_parsing(line: u64) -> Self {
Self(Content::ParseError { line })
}
#[cfg(not(feature = "unstable"))]
pub(crate) fn from_parsing(_: u64) -> Self {
Self(Content::ParseError {})
}
#[cfg(feature = "unstable")]
#[must_use]
pub fn line_number(&self) -> u64 {
match self.0 {
Content::ParseError { line } => line,
Content::ConversionError(_) => {
panic!("Cannot get the line number from a conversion error")
}
}
}
}
#[derive(Debug, Clone)]
enum Content {
ParseError {
#[cfg(feature = "unstable")]
line: u64,
},
ConversionError(ConversionError),
}