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
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("{0}")]
ParseInt(#[from] std::num::ParseIntError),
#[error("Invalid type: {0}")]
InvalidType(u8),
#[error("Invalid Textkennzeichen: {0}")]
InvalidTextkennzeichen(u8),
#[error("Invalid Regionalschluessel: {0}")]
ParseKey(#[from] ParseKeyError),
}
#[derive(Debug, Error)]
pub enum ParseKeyError {
#[error("Key has invalid length: Expected {expected}, but got {got}: {s}")]
InvalidLength {
expected: usize,
got: usize,
s: String,
},
#[error("Keys must be numeric: {0}")]
NonNumeric(String),
}
impl ParseKeyError {
pub fn invalid_length(s: &str, expected: usize) -> Self {
Self::InvalidLength {
expected,
got: s.len(),
s: s.to_owned(),
}
}
pub fn non_numeric(s: &str) -> Self {
Self::NonNumeric(s.to_owned())
}
}