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
113
114
use std;
use std::error::Error;
use std::fmt::Display;
use std::str::Utf8Error;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ReadError {
InvalidTag(u8),
MissingNullTerminator,
InvalidUtf8,
InvalidBoolValue,
InvalidFloatLength,
InvalidFdLength,
TimestampOutOfRange,
InvalidSubfield,
InvalidKeyValuePair,
InvalidFdNumber(u32),
}
impl Error for ReadError {
fn description(&self) -> &str {
#[cfg_attr(rustfmt, rustfmt_skip)]
match self {
ReadError::InvalidTag(_) => "Invalid argdata tag",
ReadError::MissingNullTerminator => "Argdata contains a string without nul terminator",
ReadError::InvalidUtf8 => "Argdata contains invalid UTF-8",
ReadError::InvalidBoolValue => "Argdata contains an invalid boolean value",
ReadError::InvalidFloatLength => "Argdata contains floating point data of invalid length",
ReadError::InvalidFdLength => "Argdata contains file descriptor data of invalid length",
ReadError::TimestampOutOfRange => "Argdata contains a timestamp which is out of the accepted range",
ReadError::InvalidSubfield => "Argdata has an incomplete subfield",
ReadError::InvalidKeyValuePair => "Argdata map has an incomplete key-value pair",
ReadError::InvalidFdNumber(_) => "Argdata contains a file descriptor that doesn't exist",
}
}
}
impl Display for ReadError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.description())?;
match self {
ReadError::InvalidTag(x) => write!(f, " (0x{:02X})", x),
ReadError::InvalidFdNumber(x) => write!(f, " ({})", *x as i32),
_ => Ok(()),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NoFit {
OutOfRange,
DifferentType,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NotRead {
NoFit(NoFit),
Error(ReadError),
}
impl From<ReadError> for NotRead {
fn from(e: ReadError) -> NotRead {
NotRead::Error(e)
}
}
impl From<NoFit> for NotRead {
fn from(e: NoFit) -> NotRead {
NotRead::NoFit(e)
}
}
impl From<Utf8Error> for ReadError {
fn from(_: Utf8Error) -> ReadError {
ReadError::InvalidUtf8
}
}
impl From<Utf8Error> for NotRead {
fn from(_: Utf8Error) -> NotRead {
NotRead::Error(ReadError::InvalidUtf8)
}
}