25
25
//! `-C target_cpu=native` allows the detection to become compile time checks,
26
26
//! making it *even* faster.
27
27
28
- use core:: { fmt, result, str} ;
28
+ use core:: { fmt, mem , result, str} ;
29
29
use core:: mem:: MaybeUninit ;
30
30
31
31
use crate :: iter:: Bytes ;
@@ -375,7 +375,7 @@ impl ParserConfig {
375
375
/// let result = httparse::ParserConfig::default()
376
376
/// .allow_space_before_first_header_name(true)
377
377
/// .parse_response(&mut response, buf);
378
-
378
+ ///
379
379
/// assert_eq!(result, Ok(httparse::Status::Complete(buf.len())));
380
380
/// assert_eq!(response.version.unwrap(), 1);
381
381
/// assert_eq!(response.code.unwrap(), 200);
@@ -580,7 +580,7 @@ impl<'h, 'b> Request<'h, 'b> {
580
580
}
581
581
582
582
fn parse_with_config ( & mut self , buf : & ' b [ u8 ] , config : & ParserConfig ) -> Result < usize > {
583
- let headers = core :: mem:: replace ( & mut self . headers , & mut [ ] ) ;
583
+ let headers = mem:: take ( & mut self . headers ) ;
584
584
585
585
/* SAFETY: see `parse_headers_iter_uninit` guarantees */
586
586
unsafe {
@@ -683,7 +683,7 @@ impl<'h, 'b> Response<'h, 'b> {
683
683
}
684
684
685
685
fn parse_with_config ( & mut self , buf : & ' b [ u8 ] , config : & ParserConfig ) -> Result < usize > {
686
- let headers = core :: mem:: replace ( & mut self . headers , & mut [ ] ) ;
686
+ let headers = mem:: take ( & mut self . headers ) ;
687
687
688
688
// SAFETY: see guarantees of [`parse_headers_iter_uninit`], which leaves no uninitialized
689
689
// headers around. On failure, the original headers are restored.
@@ -779,7 +779,7 @@ pub struct Header<'a> {
779
779
pub value : & ' a [ u8 ] ,
780
780
}
781
781
782
- impl < ' a > fmt:: Debug for Header < ' a > {
782
+ impl fmt:: Debug for Header < ' _ > {
783
783
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
784
784
let mut f = f. debug_struct ( "Header" ) ;
785
785
f. field ( "name" , & self . name ) ;
@@ -967,10 +967,10 @@ pub fn parse_uri<'a>(bytes: &mut Bytes<'a>) -> Result<&'a str> {
967
967
return Err ( Error :: Token ) ;
968
968
}
969
969
970
- return Ok ( Status :: Complete (
970
+ Ok ( Status :: Complete (
971
971
// SAFETY: all bytes up till `i` must have been `is_method_token` and therefore also utf-8.
972
972
unsafe { str:: from_utf8_unchecked ( bytes. slice_skip ( 1 ) ) } ,
973
- ) ) ;
973
+ ) )
974
974
} else {
975
975
Err ( Error :: Token )
976
976
}
@@ -1071,9 +1071,9 @@ fn parse_headers_iter_uninit<'a>(
1071
1071
num_headers : usize ,
1072
1072
}
1073
1073
1074
- impl < ' r1 , ' r2 , ' a > Drop for ShrinkOnDrop < ' r1 , ' r2 , ' a > {
1074
+ impl Drop for ShrinkOnDrop < ' _ , ' _ , ' _ > {
1075
1075
fn drop ( & mut self ) {
1076
- let headers = core :: mem:: replace ( self . headers , & mut [ ] ) ;
1076
+ let headers = mem:: take ( self . headers ) ;
1077
1077
1078
1078
/* SAFETY: num_headers is the number of initialized headers */
1079
1079
let headers = unsafe { headers. get_unchecked_mut ( ..self . num_headers ) } ;
@@ -1323,7 +1323,7 @@ pub fn parse_chunk_size(buf: &[u8])
1323
1323
return Err ( InvalidChunkSize ) ;
1324
1324
}
1325
1325
count += 1 ;
1326
- if cfg ! ( debug_assertions) && size > ( core :: u64:: MAX / RADIX ) {
1326
+ if cfg ! ( debug_assertions) && size > ( u64:: MAX / RADIX ) {
1327
1327
// actually unreachable!(), because count stops the loop at 15 digits before
1328
1328
// we can reach u64::MAX / RADIX == 0xfffffffffffffff, which requires 15 hex
1329
1329
// digits. This stops mirai reporting a false alarm regarding the `size *=
@@ -1338,7 +1338,7 @@ pub fn parse_chunk_size(buf: &[u8])
1338
1338
return Err ( InvalidChunkSize ) ;
1339
1339
}
1340
1340
count += 1 ;
1341
- if cfg ! ( debug_assertions) && size > ( core :: u64:: MAX / RADIX ) {
1341
+ if cfg ! ( debug_assertions) && size > ( u64:: MAX / RADIX ) {
1342
1342
return Err ( InvalidChunkSize ) ;
1343
1343
}
1344
1344
size *= RADIX ;
@@ -1349,7 +1349,7 @@ pub fn parse_chunk_size(buf: &[u8])
1349
1349
return Err ( InvalidChunkSize ) ;
1350
1350
}
1351
1351
count += 1 ;
1352
- if cfg ! ( debug_assertions) && size > ( core :: u64:: MAX / RADIX ) {
1352
+ if cfg ! ( debug_assertions) && size > ( u64:: MAX / RADIX ) {
1353
1353
return Err ( InvalidChunkSize ) ;
1354
1354
}
1355
1355
size *= RADIX ;
@@ -2057,7 +2057,7 @@ mod tests {
2057
2057
assert_eq ! ( parse_chunk_size( b"567f8a\r foo" ) , Err ( crate :: InvalidChunkSize ) ) ;
2058
2058
assert_eq ! ( parse_chunk_size( b"567f8a\r foo" ) , Err ( crate :: InvalidChunkSize ) ) ;
2059
2059
assert_eq ! ( parse_chunk_size( b"567xf8a\r \n " ) , Err ( crate :: InvalidChunkSize ) ) ;
2060
- assert_eq ! ( parse_chunk_size( b"ffffffffffffffff\r \n " ) , Ok ( Status :: Complete ( ( 18 , std :: u64 :: MAX ) ) ) ) ;
2060
+ assert_eq ! ( parse_chunk_size( b"ffffffffffffffff\r \n " ) , Ok ( Status :: Complete ( ( 18 , u64 :: MAX ) ) ) ) ;
2061
2061
assert_eq ! ( parse_chunk_size( b"1ffffffffffffffff\r \n " ) , Err ( crate :: InvalidChunkSize ) ) ;
2062
2062
assert_eq ! ( parse_chunk_size( b"Affffffffffffffff\r \n " ) , Err ( crate :: InvalidChunkSize ) ) ;
2063
2063
assert_eq ! ( parse_chunk_size( b"fffffffffffffffff\r \n " ) , Err ( crate :: InvalidChunkSize ) ) ;
0 commit comments