@@ -43,8 +43,8 @@ const ASCII_UPPER_F: u8 = b'F';
43
43
*
44
44
* Should everything work as designed (i.e. none of these conditions occur) a `Some` is returned.
45
45
*/
46
- pub fn read_decimal < R : Reader , N : UnsignedInt + NumCast + Int >
47
- ( reader : & mut R , expected_end: |u8| -> bool )
46
+ pub fn read_decimal < R : Reader , N : UnsignedInt + NumCast + Int , F : FnMut ( u8 ) -> bool >
47
+ ( reader : & mut R , expected_end : & mut F )
48
48
-> IoResult < N > {
49
49
// Here and in `read_hexadecimal` there is the possibility of infinite sequence of zeroes. The
50
50
// spec allows this, but it may not be a good thing to allow. It's not a particularly good
@@ -64,8 +64,7 @@ pub fn read_decimal<R: Reader, N: UnsignedInt + NumCast + Int>
64
64
None => return Err ( bad_input ( ) ) , // overflow
65
65
}
66
66
} ,
67
- Ok ( b) if got_content && expected_end ( b) => return Ok ( n) ,
68
- Ok ( _) => return Err ( bad_input ( ) ) , // not a valid number
67
+ Ok ( b) => return if got_content && expected_end ( b) { Ok ( n) } else { Err ( bad_input ( ) ) } , // not a valid number
69
68
Err ( err) => return Err ( err) , // I/O error
70
69
} ;
71
70
got_content = true ;
@@ -89,8 +88,8 @@ pub fn read_decimal<R: Reader, N: UnsignedInt + NumCast + Int>
89
88
*
90
89
* Should everything work as designed (i.e. none of these conditions occur) a `Some` is returned.
91
90
*/
92
- pub fn read_hexadecimal < R : Reader , N : UnsignedInt + NumCast + Int >
93
- ( reader : & mut R , expected_end: |u8| -> bool )
91
+ pub fn read_hexadecimal < R : Reader , N : UnsignedInt + NumCast + Int , F : FnMut ( u8 ) -> bool >
92
+ ( reader : & mut R , expected_end : & mut F )
94
93
-> IoResult < N > {
95
94
let mut n: N = Int :: zero ( ) ;
96
95
let mut got_content = false ;
@@ -118,8 +117,7 @@ pub fn read_hexadecimal<R: Reader, N: UnsignedInt + NumCast + Int>
118
117
None => return Err ( bad_input ( ) ) , // overflow
119
118
}
120
119
} ,
121
- Ok ( b) if got_content && expected_end ( b) => return Ok ( n) ,
122
- Ok ( _) => return Err ( bad_input ( ) ) , // not a valid number
120
+ Ok ( b) => return if got_content && expected_end ( b) { Ok ( n) } else { Err ( bad_input ( ) ) } , // not a valid number
123
121
Err ( err) => return Err ( err) , // I/O error
124
122
} ;
125
123
got_content = true ;
@@ -142,9 +140,9 @@ pub fn read_hexadecimal<R: Reader, N: UnsignedInt + NumCast + Int>
142
140
* - A `Some`, if all goes well.
143
141
*/
144
142
#[ inline]
145
- pub fn read_http_version < R : Reader >
146
- ( reader : & mut R , expected_end: |u8| -> bool )
147
- -> IoResult < ( uint , uint ) > {
143
+ pub fn read_http_version < R : Reader , F : FnMut ( u8 ) -> bool >
144
+ ( reader : & mut R , expected_end : & mut F )
145
+ -> IoResult < ( usize , usize ) > {
148
146
// I'd read into a [0u8, ..5], but that buffer is not guaranteed to be
149
147
// filled, so I must read it byte by byte to guarantee correctness.
150
148
// (Sure, no sane person/library would send the first packet with "HTT"
@@ -162,7 +160,7 @@ pub fn read_http_version<R: Reader>
162
160
return Err ( bad_input ( ) ) ;
163
161
}
164
162
165
- let major = try!( read_decimal ( reader, |b| b == b'.' ) ) ;
163
+ let major = try!( read_decimal ( reader, & mut |b| b == b'.' ) ) ;
166
164
let minor = try!( read_decimal ( reader, expected_end) ) ;
167
165
Ok ( ( major, minor) )
168
166
}
@@ -173,7 +171,7 @@ macro_rules! test_reads {
173
171
$(
174
172
assert_eq!(
175
173
concat_idents!( read_, $func) ( & mut MemReader :: new( $value. bytes( ) . collect:: <Vec <_>>( ) ) ,
176
- |b| b == 0 ) . ok( ) ,
174
+ & mut |b| b == 0 ) . ok( ) ,
177
175
$expected) ;
178
176
) *
179
177
} }
0 commit comments