@@ -9,31 +9,34 @@ pub(crate) enum ErrorKind {
9
9
/// Invalid character in the [`Uuid`] string.
10
10
///
11
11
/// [`Uuid`]: ../struct.Uuid.html
12
- Char { character : char , index : usize } ,
12
+ ParseChar { character : char , index : usize } ,
13
13
/// A simple [`Uuid`] didn't contain 32 characters.
14
14
///
15
15
/// [`Uuid`]: ../struct.Uuid.html
16
- SimpleLength { len : usize } ,
16
+ ParseSimpleLength { len : usize } ,
17
17
/// A byte array didn't contain 16 bytes
18
- ByteLength { len : usize } ,
18
+ ParseByteLength { len : usize } ,
19
19
/// A hyphenated [`Uuid`] didn't contain 5 groups
20
20
///
21
21
/// [`Uuid`]: ../struct.Uuid.html
22
- GroupCount { count : usize } ,
22
+ ParseGroupCount { count : usize } ,
23
23
/// A hyphenated [`Uuid`] had a group that wasn't the right length
24
24
///
25
25
/// [`Uuid`]: ../struct.Uuid.html
26
- GroupLength {
26
+ ParseGroupLength {
27
27
group : usize ,
28
28
len : usize ,
29
29
index : usize ,
30
30
} ,
31
31
/// The input was not a valid UTF8 string
32
- InvalidUTF8 ,
32
+ ParseInvalidUTF8 ,
33
+ /// Some other parsing error occurred.
34
+ ParseOther ,
33
35
/// The UUID is nil.
34
36
Nil ,
35
- /// Some other error occurred.
36
- Other ,
37
+ /// A system time was invalid.
38
+ #[ cfg( feature = "std" ) ]
39
+ InvalidSystemTime ( crate :: std:: string:: String ) ,
37
40
}
38
41
39
42
/// A string that is guaranteed to fail to parse to a [`Uuid`].
@@ -52,7 +55,7 @@ impl<'a> InvalidUuid<'a> {
52
55
// Check whether or not the input was ever actually a valid UTF8 string
53
56
let input_str = match std:: str:: from_utf8 ( self . 0 ) {
54
57
Ok ( s) => s,
55
- Err ( _) => return Error ( ErrorKind :: InvalidUTF8 ) ,
58
+ Err ( _) => return Error ( ErrorKind :: ParseInvalidUTF8 ) ,
56
59
} ;
57
60
58
61
let ( uuid_str, offset, simple) = match input_str. as_bytes ( ) {
@@ -74,7 +77,7 @@ impl<'a> InvalidUuid<'a> {
74
77
let byte = character as u8 ;
75
78
if character as u32 - byte as u32 > 0 {
76
79
// Multibyte char
77
- return Error ( ErrorKind :: Char {
80
+ return Error ( ErrorKind :: ParseChar {
78
81
character,
79
82
index : index + offset + 1 ,
80
83
} ) ;
@@ -86,7 +89,7 @@ impl<'a> InvalidUuid<'a> {
86
89
hyphen_count += 1 ;
87
90
} else if !byte. is_ascii_hexdigit ( ) {
88
91
// Non-hex char
89
- return Error ( ErrorKind :: Char {
92
+ return Error ( ErrorKind :: ParseChar {
90
93
character : byte as char ,
91
94
index : index + offset + 1 ,
92
95
} ) ;
@@ -97,21 +100,21 @@ impl<'a> InvalidUuid<'a> {
97
100
// This means that we tried and failed to parse a simple uuid.
98
101
// Since we verified that all the characters are valid, this means
99
102
// that it MUST have an invalid length.
100
- Error ( ErrorKind :: SimpleLength {
103
+ Error ( ErrorKind :: ParseSimpleLength {
101
104
len : input_str. len ( ) ,
102
105
} )
103
106
} else if hyphen_count != 4 {
104
107
// We tried to parse a hyphenated variant, but there weren't
105
108
// 5 groups (4 hyphen splits).
106
- Error ( ErrorKind :: GroupCount {
109
+ Error ( ErrorKind :: ParseGroupCount {
107
110
count : hyphen_count + 1 ,
108
111
} )
109
112
} else {
110
113
// There are 5 groups, one of them has an incorrect length
111
114
const BLOCK_STARTS : [ usize ; 5 ] = [ 0 , 9 , 14 , 19 , 24 ] ;
112
115
for i in 0 ..4 {
113
116
if group_bounds[ i] != BLOCK_STARTS [ i + 1 ] - 1 {
114
- return Error ( ErrorKind :: GroupLength {
117
+ return Error ( ErrorKind :: ParseGroupLength {
115
118
group : i,
116
119
len : group_bounds[ i] - BLOCK_STARTS [ i] ,
117
120
index : offset + BLOCK_STARTS [ i] + 1 ,
@@ -120,7 +123,7 @@ impl<'a> InvalidUuid<'a> {
120
123
}
121
124
122
125
// The last group must be too long
123
- Error ( ErrorKind :: GroupLength {
126
+ Error ( ErrorKind :: ParseGroupLength {
124
127
group : 4 ,
125
128
len : input_str. len ( ) - BLOCK_STARTS [ 4 ] ,
126
129
index : offset + BLOCK_STARTS [ 4 ] + 1 ,
@@ -133,35 +136,37 @@ impl<'a> InvalidUuid<'a> {
133
136
impl fmt:: Display for Error {
134
137
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
135
138
match self . 0 {
136
- ErrorKind :: Char {
139
+ ErrorKind :: ParseChar {
137
140
character, index, ..
138
141
} => {
139
142
write ! ( f, "invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-fA-F-], found `{}` at {}" , character, index)
140
143
}
141
- ErrorKind :: SimpleLength { len } => {
144
+ ErrorKind :: ParseSimpleLength { len } => {
142
145
write ! (
143
146
f,
144
147
"invalid length: expected length 32 for simple format, found {}" ,
145
148
len
146
149
)
147
150
}
148
- ErrorKind :: ByteLength { len } => {
151
+ ErrorKind :: ParseByteLength { len } => {
149
152
write ! ( f, "invalid length: expected 16 bytes, found {}" , len)
150
153
}
151
- ErrorKind :: GroupCount { count } => {
154
+ ErrorKind :: ParseGroupCount { count } => {
152
155
write ! ( f, "invalid group count: expected 5, found {}" , count)
153
156
}
154
- ErrorKind :: GroupLength { group, len, .. } => {
157
+ ErrorKind :: ParseGroupLength { group, len, .. } => {
155
158
let expected = [ 8 , 4 , 4 , 4 , 12 ] [ group] ;
156
159
write ! (
157
160
f,
158
161
"invalid group length in group {}: expected {}, found {}" ,
159
162
group, expected, len
160
163
)
161
164
}
162
- ErrorKind :: InvalidUTF8 => write ! ( f, "non-UTF8 input" ) ,
165
+ ErrorKind :: ParseInvalidUTF8 => write ! ( f, "non-UTF8 input" ) ,
163
166
ErrorKind :: Nil => write ! ( f, "the UUID is nil" ) ,
164
- ErrorKind :: Other => write ! ( f, "failed to parse a UUID" ) ,
167
+ ErrorKind :: ParseOther => write ! ( f, "failed to parse a UUID" ) ,
168
+ #[ cfg( feature = "std" ) ]
169
+ ErrorKind :: InvalidSystemTime ( ref e) => write ! ( f, "the system timestamp is invalid: {e}" ) ,
165
170
}
166
171
}
167
172
}
@@ -171,5 +176,5 @@ mod std_support {
171
176
use super :: * ;
172
177
use crate :: std:: error;
173
178
174
- impl error:: Error for Error { }
179
+ impl error:: Error for Error { }
175
180
}
0 commit comments