Skip to content

Commit 6b59bd2

Browse files
committed
refactor(hyper): Fix a few nits
1 parent 92ee51a commit 6b59bd2

File tree

8 files changed

+18
-34
lines changed

8 files changed

+18
-34
lines changed

src/header/common/access_control_allow_origin.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ impl header::Header for AccessControlAllowOrigin {
5252
impl header::HeaderFormat for AccessControlAllowOrigin {
5353
fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result {
5454
match *self {
55-
AccessControlAllowOrigin::Any => write!(f, "*"),
56-
AccessControlAllowOrigin::Value(ref url) =>
57-
write!(f, "{}", url)
55+
AccessControlAllowOrigin::Any => f.write_str("*"),
56+
AccessControlAllowOrigin::Value(ref url) => fmt::Display::fmt(url, f)
5857
}
5958
}
6059
}

src/header/common/authorization.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ impl<S: Scheme + Any> Header for Authorization<S> where <S as FromStr>::Err: 'st
4545
}
4646

4747
impl<S: Scheme + Any> HeaderFormat for Authorization<S> where <S as FromStr>::Err: 'static {
48-
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
49-
match <S as Scheme>::scheme() {
50-
Some(scheme) => try!(write!(fmt, "{} ", scheme)),
51-
None => ()
48+
fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result {
49+
if let Some(scheme) = <S as Scheme>::scheme() {
50+
try!(write!(f, "{} ", scheme))
5251
};
53-
self.0.fmt_scheme(fmt)
52+
self.0.fmt_scheme(f)
5453
}
5554
}
5655

@@ -70,7 +69,7 @@ impl Scheme for String {
7069
}
7170

7271
fn fmt_scheme(&self, f: &mut fmt::Formatter) -> fmt::Result {
73-
write!(f, "{}", self)
72+
fmt::Display::fmt(self, f)
7473
}
7574
}
7675

@@ -190,4 +189,3 @@ mod tests {
190189

191190
bench_header!(raw, Authorization<String>, { vec![b"foo bar baz".to_vec()] });
192191
bench_header!(basic, Authorization<Basic>, { vec![b"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==".to_vec()] });
193-

src/header/common/cache_control.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl Header for CacheControl {
1919
.filter_map(|line| from_one_comma_delimited(&line[..]))
2020
.collect::<Vec<Vec<CacheDirective>>>()
2121
.concat();
22-
if directives.len() > 0 {
22+
if !directives.is_empty() {
2323
Some(CacheControl(directives))
2424
} else {
2525
None

src/header/common/pragma.rs

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ impl Header for Pragma {
3333
parsing::from_one_raw_str(raw).and_then(|s: String| {
3434
let slice = &s.to_ascii_lowercase()[..];
3535
match slice {
36-
"" => None,
3736
"no-cache" => Some(Pragma::NoCache),
3837
_ => Some(Pragma::Ext(s)),
3938
}

src/header/common/set_cookie.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,12 @@ impl Header for SetCookie {
2222

2323
fn parse_header(raw: &[Vec<u8>]) -> Option<SetCookie> {
2424
let mut set_cookies = Vec::with_capacity(raw.len());
25-
for set_cookies_raw in raw.iter() {
26-
match from_utf8(&set_cookies_raw[..]) {
27-
Ok(s) if !s.is_empty() => {
28-
match s.parse() {
29-
Ok(cookie) => set_cookies.push(cookie),
30-
Err(_) => ()
31-
}
32-
},
33-
_ => ()
34-
};
25+
for set_cookies_raw in raw {
26+
if let Ok(s) = from_utf8(&set_cookies_raw[..]) {
27+
if let Ok(cookie) = s.parse() {
28+
set_cookies.push(cookie);
29+
}
30+
}
3531
}
3632

3733
if !set_cookies.is_empty() {

src/header/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,7 @@ impl<'a> Iterator for HeadersItems<'a> {
252252
type Item = HeaderView<'a>;
253253

254254
fn next(&mut self) -> Option<HeaderView<'a>> {
255-
match self.inner.next() {
256-
Some((k, v)) => Some(HeaderView(k, v)),
257-
None => None
258-
}
255+
self.inner.next().map(|(k, v)| HeaderView(k, v))
259256
}
260257
}
261258

src/header/shared/httpdate.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ impl FromStr for HttpDate {
4646

4747
impl Display for HttpDate {
4848
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
49-
let tm = self.0;
50-
let tm = match tm.tm_utcoff {
51-
0 => tm,
52-
_ => tm.to_utc(),
53-
};
54-
fmt::Display::fmt(&tm.rfc822(), f)
49+
fmt::Display::fmt(&self.0.to_utc().rfc822(), f)
5550
}
5651
}
5752

src/http.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl<W: Write> Write for HttpWriter<W> {
300300
}
301301
},
302302
EmptyWriter(..) => {
303-
if msg.len() != 0 {
303+
if !msg.is_empty() {
304304
error!("Cannot include a body with this kind of message");
305305
}
306306
Ok(0)
@@ -354,7 +354,7 @@ fn parse<R: Read, T: TryParse<Subject=I>, I>(rdr: &mut BufReader<R>) -> HttpResu
354354
_partial => ()
355355
}
356356
match try!(rdr.read_into_buf()) {
357-
0 if rdr.get_buf().len() == 0 => {
357+
0 if rdr.get_buf().is_empty() => {
358358
return Err(HttpIoError(io::Error::new(
359359
io::ErrorKind::ConnectionAborted,
360360
"Connection closed"

0 commit comments

Comments
 (0)