Skip to content

Commit 4cd6ca7

Browse files
davidbarskyseanmonstar
authored andcommitted
Upgrade to 2018 Edition (#331)
* 2018 edition, babey! * run `cargo fix --edition-idioms` * yes, we do intend to drop the iterator, thanks rustc! * cargo fmt * aggressive min rustc version bump to fix travis * 1.37 is not out, oops
1 parent 39931eb commit 4cd6ca7

31 files changed

+744
-727
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ matrix:
1414
- rustup target add wasm32-unknown-unknown
1515
- cargo build --target=wasm32-unknown-unknown
1616
# minimum rustc version
17-
- rust: 1.30.0
17+
- rust: 1.36.0
1818
script: cargo build
1919

2020
script:

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ A set of types for representing HTTP requests and responses.
2020
"""
2121
keywords = ["http"]
2222
categories = ["web-programming"]
23+
edition = "2018"
2324

2425
# 0.2.x isn't ready just yet
2526
publish = false

benches/header_map/basic.rs

+35-26
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ macro_rules! bench {
22
($name:ident($map:ident, $b:ident) $body:expr) => {
33
mod $name {
44
#[allow(unused_imports)]
5-
use test::{self, Bencher};
6-
use seahash::SeaHasher;
5+
use super::custom_hdr;
76
use fnv::FnvHasher;
8-
use std::hash::BuildHasherDefault;
97
use http::header::*;
8+
use seahash::SeaHasher;
9+
use std::hash::BuildHasherDefault;
1010
#[allow(unused_imports)]
11-
use super::custom_hdr;
11+
use test::{self, Bencher};
1212

1313
#[bench]
1414
fn header_map($b: &mut Bencher) {
@@ -25,7 +25,7 @@ macro_rules! bench {
2525

2626
#[bench]
2727
fn vec_map($b: &mut Bencher) {
28-
use vec_map::VecMap;
28+
use crate::vec_map::VecMap;
2929

3030
let $map = || VecMap::with_capacity(0);
3131
$body
@@ -208,7 +208,6 @@ bench!(set_10_get_1_custom_short(new_map, b) {
208208
})
209209
});
210210

211-
212211
bench!(set_10_get_1_custom_med(new_map, b) {
213212
let hdrs = super::med_custom_hdr(10);
214213

@@ -474,38 +473,48 @@ bench!(hn_hdrs_set_11_get_with_miss(new_map, b) {
474473
use http::header::*;
475474

476475
fn custom_hdr(n: usize) -> Vec<HeaderName> {
477-
(0..n).map(|i| {
478-
let s = format!("x-custom-{}", i);
479-
s.parse().unwrap()
480-
}).collect()
476+
(0..n)
477+
.map(|i| {
478+
let s = format!("x-custom-{}", i);
479+
s.parse().unwrap()
480+
})
481+
.collect()
481482
}
482483

483484
fn med_custom_hdr(n: usize) -> Vec<HeaderName> {
484-
(0..n).map(|i| {
485-
let s = format!("content-length-{}", i);
486-
s.parse().unwrap()
487-
}).collect()
485+
(0..n)
486+
.map(|i| {
487+
let s = format!("content-length-{}", i);
488+
s.parse().unwrap()
489+
})
490+
.collect()
488491
}
489492

490493
fn long_custom_hdr(n: usize) -> Vec<HeaderName> {
491-
(0..n).map(|i| {
492-
let s = format!("access-control-allow-headers-{}", i);
493-
s.parse().unwrap()
494-
}).collect()
494+
(0..n)
495+
.map(|i| {
496+
let s = format!("access-control-allow-headers-{}", i);
497+
s.parse().unwrap()
498+
})
499+
.collect()
495500
}
496501

497502
fn very_long_custom_hdr(n: usize) -> Vec<HeaderName> {
498-
(0..n).map(|i| {
499-
let s = format!("access-control-allow-access-control-allow-headers-{}", i);
500-
s.parse().unwrap()
501-
}).collect()
503+
(0..n)
504+
.map(|i| {
505+
let s = format!("access-control-allow-access-control-allow-headers-{}", i);
506+
s.parse().unwrap()
507+
})
508+
.collect()
502509
}
503510

504511
fn custom_std(n: usize) -> Vec<HeaderName> {
505-
(0..n).map(|i| {
506-
let s = format!("{}-{}", STD[i % STD.len()].as_str(), i);
507-
s.parse().unwrap()
508-
}).collect()
512+
(0..n)
513+
.map(|i| {
514+
let s = format!("{}-{}", STD[i % STD.len()].as_str(), i);
515+
s.parse().unwrap()
516+
})
517+
.collect()
509518
}
510519

511520
const STD: &'static [HeaderName] = &[

benches/header_map/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#![feature(test)]
22

3-
extern crate http;
43
extern crate test;
5-
extern crate indexmap;
6-
extern crate seahash;
7-
extern crate fnv;
84

95
mod basic;
106
mod vec_map;

benches/header_map/vec_map.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ impl<K: PartialEq, V> VecMap<K, V> {
99
#[inline]
1010
pub fn with_capacity(cap: usize) -> VecMap<K, V> {
1111
VecMap {
12-
vec: Vec::with_capacity(cap)
12+
vec: Vec::with_capacity(cap),
1313
}
1414
}
1515

1616
#[inline]
1717
pub fn insert(&mut self, key: K, value: V) {
1818
match self.find(&key) {
1919
Some(pos) => self.vec[pos] = (key, value),
20-
None => self.vec.push((key, value))
20+
None => self.vec.push((key, value)),
2121
}
2222
}
2323

2424
#[inline]
25-
pub fn entry(&mut self, key: K) -> Entry<K, V> {
25+
pub fn entry(&mut self, key: K) -> Entry<'_, K, V> {
2626
match self.find(&key) {
2727
Some(pos) => Entry::Occupied(OccupiedEntry {
2828
vec: self,
@@ -31,7 +31,7 @@ impl<K: PartialEq, V> VecMap<K, V> {
3131
None => Entry::Vacant(VacantEntry {
3232
vec: self,
3333
key: key,
34-
})
34+
}),
3535
}
3636
}
3737

@@ -51,15 +51,19 @@ impl<K: PartialEq, V> VecMap<K, V> {
5151
}
5252

5353
#[inline]
54-
pub fn len(&self) -> usize { self.vec.len() }
54+
pub fn len(&self) -> usize {
55+
self.vec.len()
56+
}
5557

5658
#[inline]
57-
pub fn iter(&self) -> ::std::slice::Iter<(K, V)> {
59+
pub fn iter(&self) -> ::std::slice::Iter<'_, (K, V)> {
5860
self.vec.iter()
5961
}
6062
#[inline]
6163
pub fn remove<K2: PartialEq<K> + ?Sized>(&mut self, key: &K2) -> Option<V> {
62-
self.find(key).map(|pos| self.vec.remove(pos)).map(|(_, v)| v)
64+
self.find(key)
65+
.map(|pos| self.vec.remove(pos))
66+
.map(|(_, v)| v)
6367
}
6468
#[inline]
6569
pub fn clear(&mut self) {
@@ -74,10 +78,10 @@ impl<K: PartialEq, V> VecMap<K, V> {
7478

7579
pub enum Entry<'a, K: 'a, V: 'a> {
7680
Vacant(VacantEntry<'a, K, V>),
77-
Occupied(OccupiedEntry<'a, K, V>)
81+
Occupied(OccupiedEntry<'a, K, V>),
7882
}
7983

80-
pub struct VacantEntry<'a, K: 'a, V: 'a> {
84+
pub struct VacantEntry<'a, K, V> {
8185
vec: &'a mut VecMap<K, V>,
8286
key: K,
8387
}
@@ -91,7 +95,7 @@ impl<'a, K, V> VacantEntry<'a, K, V> {
9195
}
9296
}
9397

94-
pub struct OccupiedEntry<'a, K: 'a, V: 'a> {
98+
pub struct OccupiedEntry<'a, K, V> {
9599
vec: &'a mut VecMap<K, V>,
96100
pos: usize,
97101
}

benches/header_value.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![feature(test)]
22

3-
extern crate bytes;
4-
extern crate http;
53
extern crate test;
64

75
use bytes::Bytes;
@@ -11,7 +9,6 @@ use test::Bencher;
119
static SHORT: &'static [u8] = b"localhost";
1210
static LONG: &'static [u8] = b"Mozilla/5.0 (X11; CrOS x86_64 9592.71.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.80 Safari/537.36";
1311

14-
1512
#[bench]
1613
fn from_shared_short(b: &mut Bencher) {
1714
b.bytes = SHORT.len() as u64;
@@ -30,25 +27,20 @@ fn from_shared_long(b: &mut Bencher) {
3027
});
3128
}
3229

33-
3430
#[bench]
3531
fn from_shared_unchecked_short(b: &mut Bencher) {
3632
b.bytes = SHORT.len() as u64;
3733
let bytes = Bytes::from_static(SHORT);
38-
b.iter(|| {
39-
unsafe {
40-
HeaderValue::from_shared_unchecked(bytes.clone());
41-
}
34+
b.iter(|| unsafe {
35+
HeaderValue::from_shared_unchecked(bytes.clone());
4236
});
4337
}
4438

4539
#[bench]
4640
fn from_shared_unchecked_long(b: &mut Bencher) {
4741
b.bytes = LONG.len() as u64;
4842
let bytes = Bytes::from_static(LONG);
49-
b.iter(|| {
50-
unsafe {
51-
HeaderValue::from_shared_unchecked(bytes.clone());
52-
}
43+
b.iter(|| unsafe {
44+
HeaderValue::from_shared_unchecked(bytes.clone());
5345
});
5446
}

benches/uri.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![feature(test)]
22

3-
extern crate http;
43
extern crate test;
54

65
use http::Uri;

src/byte_str.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,27 @@ pub(crate) struct ByteStr {
1010
impl ByteStr {
1111
#[inline]
1212
pub fn new() -> ByteStr {
13-
ByteStr { bytes: Bytes::new() }
13+
ByteStr {
14+
bytes: Bytes::new(),
15+
}
1416
}
1517

1618
#[inline]
1719
pub fn from_static(val: &'static str) -> ByteStr {
18-
ByteStr { bytes: Bytes::from_static(val.as_bytes()) }
20+
ByteStr {
21+
bytes: Bytes::from_static(val.as_bytes()),
22+
}
1923
}
2024

2125
#[inline]
2226
pub unsafe fn from_utf8_unchecked(bytes: Bytes) -> ByteStr {
2327
if cfg!(debug_assertions) {
2428
match str::from_utf8(&bytes) {
2529
Ok(_) => (),
26-
Err(err) => panic!("ByteStr::from_utf8_unchecked() with invalid bytes; error = {}, bytes = {:?}", err, bytes),
30+
Err(err) => panic!(
31+
"ByteStr::from_utf8_unchecked() with invalid bytes; error = {}, bytes = {:?}",
32+
err, bytes
33+
),
2734
}
2835
}
2936
ByteStr { bytes: bytes }
@@ -43,14 +50,18 @@ impl ops::Deref for ByteStr {
4350
impl From<String> for ByteStr {
4451
#[inline]
4552
fn from(src: String) -> ByteStr {
46-
ByteStr { bytes: Bytes::from(src) }
53+
ByteStr {
54+
bytes: Bytes::from(src),
55+
}
4756
}
4857
}
4958

5059
impl<'a> From<&'a str> for ByteStr {
5160
#[inline]
5261
fn from(src: &'a str) -> ByteStr {
53-
ByteStr { bytes: Bytes::from(src) }
62+
ByteStr {
63+
bytes: Bytes::from(src),
64+
}
5465
}
5566
}
5667

src/convert.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use Error;
2-
use header::{HeaderName, HeaderValue};
3-
use method::Method;
4-
use sealed::Sealed;
5-
use status::StatusCode;
6-
use uri::{Scheme, Authority, PathAndQuery, Uri};
1+
use crate::header::{HeaderName, HeaderValue};
2+
use crate::method::Method;
3+
use crate::sealed::Sealed;
4+
use crate::status::StatusCode;
5+
use crate::uri::{Authority, PathAndQuery, Scheme, Uri};
6+
use crate::Error;
77

88
/// Private trait for the `http` crate to have generic methods with fallible
99
/// conversions.
@@ -33,8 +33,7 @@ where
3333
T: Sized,
3434
{
3535
fn http_try_into(self) -> Result<U, Error> {
36-
HttpTryFrom::try_from(self)
37-
.map_err(|e: U::Error| e.into())
36+
HttpTryFrom::try_from(self).map_err(|e: U::Error| e.into())
3837
}
3938
}
4039

0 commit comments

Comments
 (0)