@@ -32,7 +32,7 @@ macro_rules! impl_helper {
32
32
} ) * )
33
33
}
34
34
35
- impl_helper ! { u8 u16 }
35
+ impl_helper ! { u8 u16 u32 }
36
36
37
37
struct Parser < ' a > {
38
38
// parsing as ASCII, so can use byte array
@@ -75,9 +75,12 @@ impl<'a> Parser<'a> {
75
75
} )
76
76
}
77
77
78
- /// Read the next character from the input if it matches the target
79
- fn read_given_char ( & mut self , target : char ) -> Option < char > {
80
- self . read_atomically ( |p| p. read_char ( ) . filter ( |& c| c == target) )
78
+ #[ must_use]
79
+ /// Read the next character from the input if it matches the target.
80
+ fn read_given_char ( & mut self , target : char ) -> Option < ( ) > {
81
+ self . read_atomically ( |p| {
82
+ p. read_char ( ) . and_then ( |c| if c == target { Some ( ( ) ) } else { None } )
83
+ } )
81
84
}
82
85
83
86
/// Helper for reading separators in an indexed loop. Reads the separator
@@ -90,7 +93,7 @@ impl<'a> Parser<'a> {
90
93
{
91
94
self . read_atomically ( move |p| {
92
95
if index > 0 {
93
- let _ = p. read_given_char ( sep) ?;
96
+ p. read_given_char ( sep) ?;
94
97
}
95
98
inner ( p)
96
99
} )
@@ -187,8 +190,8 @@ impl<'a> Parser<'a> {
187
190
188
191
// read `::` if previous code parsed less than 8 groups
189
192
// `::` indicates one or more groups of 16 bits of zeros
190
- let _ = p. read_given_char ( ':' ) ?;
191
- let _ = p. read_given_char ( ':' ) ?;
193
+ p. read_given_char ( ':' ) ?;
194
+ p. read_given_char ( ':' ) ?;
192
195
193
196
// Read the back part of the address. The :: must contain at least one
194
197
// set of zeroes, so our max length is 7.
@@ -211,7 +214,15 @@ impl<'a> Parser<'a> {
211
214
/// Read a : followed by a port in base 10.
212
215
fn read_port ( & mut self ) -> Option < u16 > {
213
216
self . read_atomically ( |p| {
214
- let _ = p. read_given_char ( ':' ) ?;
217
+ p. read_given_char ( ':' ) ?;
218
+ p. read_number ( 10 , None )
219
+ } )
220
+ }
221
+
222
+ /// Read a % followed by a scope id in base 10.
223
+ fn read_scope_id ( & mut self ) -> Option < u32 > {
224
+ self . read_atomically ( |p| {
225
+ p. read_given_char ( '%' ) ?;
215
226
p. read_number ( 10 , None )
216
227
} )
217
228
}
@@ -228,12 +239,13 @@ impl<'a> Parser<'a> {
228
239
/// Read an IPV6 address with a port
229
240
fn read_socket_addr_v6 ( & mut self ) -> Option < SocketAddrV6 > {
230
241
self . read_atomically ( |p| {
231
- let _ = p. read_given_char ( '[' ) ?;
242
+ p. read_given_char ( '[' ) ?;
232
243
let ip = p. read_ipv6_addr ( ) ?;
233
- let _ = p. read_given_char ( ']' ) ?;
244
+ let scope_id = p. read_scope_id ( ) . unwrap_or ( 0 ) ;
245
+ p. read_given_char ( ']' ) ?;
234
246
235
247
let port = p. read_port ( ) ?;
236
- Some ( SocketAddrV6 :: new ( ip, port, 0 , 0 ) )
248
+ Some ( SocketAddrV6 :: new ( ip, port, 0 , scope_id ) )
237
249
} )
238
250
}
239
251
0 commit comments