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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
use core::fmt;
#[allow(clippy::module_name_repetitions)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct OffsetDateTimeRangeError;
impl fmt::Display for OffsetDateTimeRangeError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "date time is out of range")
}
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
impl std::error::Error for OffsetDateTimeRangeError {}
#[allow(clippy::module_name_repetitions)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct FileTimeRangeError(FileTimeRangeErrorKind);
impl FileTimeRangeError {
#[inline]
pub(crate) const fn new(kind: FileTimeRangeErrorKind) -> Self {
Self(kind)
}
}
impl fmt::Display for FileTimeRangeError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.0 {
FileTimeRangeErrorKind::Negative => {
write!(f, "file time is before `1601-01-01 00:00:00 UTC`")
}
FileTimeRangeErrorKind::Overflow => {
write!(
f,
"file time is after `+60056-05-28 05:36:10.955161500 UTC`"
)
}
}
}
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
impl std::error::Error for FileTimeRangeError {}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum FileTimeRangeErrorKind {
Negative,
Overflow,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn clone_offset_date_time_range_error() {
assert_eq!(OffsetDateTimeRangeError.clone(), OffsetDateTimeRangeError);
}
#[test]
fn copy_offset_date_time_range_error() {
let a = OffsetDateTimeRangeError;
let b = a;
assert_eq!(a, b);
}
#[test]
fn debug_offset_date_time_range_error() {
assert_eq!(
format!("{OffsetDateTimeRangeError:?}"),
"OffsetDateTimeRangeError"
);
}
#[test]
fn partial_eq_offset_date_time_range_error() {
assert!(OffsetDateTimeRangeError == OffsetDateTimeRangeError);
}
#[test]
fn display_offset_date_time_range_error() {
assert_eq!(
format!("{OffsetDateTimeRangeError}"),
"date time is out of range"
);
}
#[cfg(feature = "std")]
#[test]
fn source_offset_date_time_range_error() {
use std::error::Error;
assert!(OffsetDateTimeRangeError.source().is_none());
}
#[test]
fn clone_file_time_range_error() {
assert_eq!(
FileTimeRangeError::new(FileTimeRangeErrorKind::Negative).clone(),
FileTimeRangeError::new(FileTimeRangeErrorKind::Negative)
);
assert_eq!(
FileTimeRangeError::new(FileTimeRangeErrorKind::Overflow).clone(),
FileTimeRangeError::new(FileTimeRangeErrorKind::Overflow)
);
}
#[test]
fn copy_file_time_range_error() {
let a = FileTimeRangeError::new(FileTimeRangeErrorKind::Negative);
let b = a;
assert_eq!(a, b);
let c = FileTimeRangeError::new(FileTimeRangeErrorKind::Overflow);
let d = c;
assert_eq!(c, d);
}
#[test]
fn debug_file_time_range_error() {
assert_eq!(
format!(
"{:?}",
FileTimeRangeError::new(FileTimeRangeErrorKind::Negative)
),
"FileTimeRangeError(Negative)"
);
assert_eq!(
format!(
"{:?}",
FileTimeRangeError::new(FileTimeRangeErrorKind::Overflow)
),
"FileTimeRangeError(Overflow)"
);
}
#[test]
fn partial_eq_file_time_range_error() {
assert!(
FileTimeRangeError::new(FileTimeRangeErrorKind::Negative)
== FileTimeRangeError::new(FileTimeRangeErrorKind::Negative)
);
assert!(
FileTimeRangeError::new(FileTimeRangeErrorKind::Overflow)
== FileTimeRangeError::new(FileTimeRangeErrorKind::Overflow)
);
}
#[test]
fn display_file_time_range_error() {
assert_eq!(
format!(
"{}",
FileTimeRangeError::new(FileTimeRangeErrorKind::Negative)
),
"file time is before `1601-01-01 00:00:00 UTC`"
);
assert_eq!(
format!(
"{}",
FileTimeRangeError::new(FileTimeRangeErrorKind::Overflow)
),
"file time is after `+60056-05-28 05:36:10.955161500 UTC`"
);
}
#[cfg(feature = "std")]
#[test]
fn source_file_time_range_error() {
use std::error::Error;
assert!(FileTimeRangeError::new(FileTimeRangeErrorKind::Negative)
.source()
.is_none());
assert!(FileTimeRangeError::new(FileTimeRangeErrorKind::Overflow)
.source()
.is_none());
}
}