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
115
116
117
118
119
120
121
122
use std::error;
use std::fmt;
use std::io;
use std::string;
#[derive(Debug)]
pub enum DecodeError {
Io(io::Error),
String(string::FromUtf8Error),
Unknown {
marker: u8,
},
Unsupported {
marker: u8,
},
UnexpectedObjectEnd,
CircularReference {
index: usize,
},
OutOfRangeReference {
index: usize,
},
NonZeroTimeZone {
offset: i16,
},
InvalidDate {
millis: f64,
},
ExternalizableType {
name: String,
},
}
impl error::Error for DecodeError {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
use self::DecodeError::*;
match *self {
Io(ref x) => x.source(),
String(ref x) => x.source(),
_ => None,
}
}
}
impl fmt::Display for DecodeError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::DecodeError::*;
match *self {
Io(ref x) => write!(f, "I/O Error: {}", x),
String(ref x) => write!(f, "Invalid String: {}", x),
Unknown { marker } => write!(f, "Unknown marker: {}", marker),
Unsupported { marker } => write!(f, "Unsupported type: maker={}", marker),
UnexpectedObjectEnd => write!(f, "Unexpected occurrence of object-end-marker"),
CircularReference { index } => {
write!(f, "Circular references are unsupported: index={}", index)
}
OutOfRangeReference { index } => write!(f, "Reference index {} is out-of-range", index),
NonZeroTimeZone { offset } => {
write!(f, "Non zero time zone offset {} is unsupported", offset)
}
InvalidDate { millis } => write!(f, "Invalid date value {}", millis),
ExternalizableType { ref name } => {
write!(f, "Externalizable type {:?} is unsupported", name)
}
}
}
}
impl PartialEq for DecodeError {
fn eq(&self, other: &Self) -> bool {
use self::DecodeError::*;
match (self, other) {
(&Unknown { marker: x }, &Unknown { marker: y }) => x == y,
(&Unsupported { marker: x }, &Unsupported { marker: y }) => x == y,
(&UnexpectedObjectEnd, &UnexpectedObjectEnd) => true,
(&CircularReference { index: x }, &CircularReference { index: y }) => x == y,
(&OutOfRangeReference { index: x }, &OutOfRangeReference { index: y }) => x == y,
(&NonZeroTimeZone { offset: x }, &NonZeroTimeZone { offset: y }) => x == y,
(&InvalidDate { millis: x }, &InvalidDate { millis: y }) => x == y,
(&ExternalizableType { name: ref x }, &ExternalizableType { name: ref y }) => x == y,
_ => false,
}
}
}
impl From<io::Error> for DecodeError {
fn from(f: io::Error) -> Self {
DecodeError::Io(f)
}
}
impl From<string::FromUtf8Error> for DecodeError {
fn from(f: string::FromUtf8Error) -> Self {
DecodeError::String(f)
}
}