Skip to content

Commit

Permalink
refactor(hyper): Fix a few nits
Browse files Browse the repository at this point in the history
  • Loading branch information
pyfisch committed May 1, 2015
1 parent 92ee51a commit 6b59bd2
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 34 deletions.
5 changes: 2 additions & 3 deletions src/header/common/access_control_allow_origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ impl header::Header for AccessControlAllowOrigin {
impl header::HeaderFormat for AccessControlAllowOrigin {
fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
AccessControlAllowOrigin::Any => write!(f, "*"),
AccessControlAllowOrigin::Value(ref url) =>
write!(f, "{}", url)
AccessControlAllowOrigin::Any => f.write_str("*"),
AccessControlAllowOrigin::Value(ref url) => fmt::Display::fmt(url, f)
}
}
}
12 changes: 5 additions & 7 deletions src/header/common/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ impl<S: Scheme + Any> Header for Authorization<S> where <S as FromStr>::Err: 'st
}

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

Expand All @@ -70,7 +69,7 @@ impl Scheme for String {
}

fn fmt_scheme(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self)
fmt::Display::fmt(self, f)
}
}

Expand Down Expand Up @@ -190,4 +189,3 @@ mod tests {

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

2 changes: 1 addition & 1 deletion src/header/common/cache_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Header for CacheControl {
.filter_map(|line| from_one_comma_delimited(&line[..]))
.collect::<Vec<Vec<CacheDirective>>>()
.concat();
if directives.len() > 0 {
if !directives.is_empty() {
Some(CacheControl(directives))
} else {
None
Expand Down
1 change: 0 additions & 1 deletion src/header/common/pragma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ impl Header for Pragma {
parsing::from_one_raw_str(raw).and_then(|s: String| {
let slice = &s.to_ascii_lowercase()[..];
match slice {
"" => None,
"no-cache" => Some(Pragma::NoCache),
_ => Some(Pragma::Ext(s)),
}
Expand Down
16 changes: 6 additions & 10 deletions src/header/common/set_cookie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@ impl Header for SetCookie {

fn parse_header(raw: &[Vec<u8>]) -> Option<SetCookie> {
let mut set_cookies = Vec::with_capacity(raw.len());
for set_cookies_raw in raw.iter() {
match from_utf8(&set_cookies_raw[..]) {
Ok(s) if !s.is_empty() => {
match s.parse() {
Ok(cookie) => set_cookies.push(cookie),
Err(_) => ()
}
},
_ => ()
};
for set_cookies_raw in raw {
if let Ok(s) = from_utf8(&set_cookies_raw[..]) {
if let Ok(cookie) = s.parse() {
set_cookies.push(cookie);
}
}
}

if !set_cookies.is_empty() {
Expand Down
5 changes: 1 addition & 4 deletions src/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,7 @@ impl<'a> Iterator for HeadersItems<'a> {
type Item = HeaderView<'a>;

fn next(&mut self) -> Option<HeaderView<'a>> {
match self.inner.next() {
Some((k, v)) => Some(HeaderView(k, v)),
None => None
}
self.inner.next().map(|(k, v)| HeaderView(k, v))
}
}

Expand Down
7 changes: 1 addition & 6 deletions src/header/shared/httpdate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ impl FromStr for HttpDate {

impl Display for HttpDate {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let tm = self.0;
let tm = match tm.tm_utcoff {
0 => tm,
_ => tm.to_utc(),
};
fmt::Display::fmt(&tm.rfc822(), f)
fmt::Display::fmt(&self.0.to_utc().rfc822(), f)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ impl<W: Write> Write for HttpWriter<W> {
}
},
EmptyWriter(..) => {
if msg.len() != 0 {
if !msg.is_empty() {
error!("Cannot include a body with this kind of message");
}
Ok(0)
Expand Down Expand Up @@ -354,7 +354,7 @@ fn parse<R: Read, T: TryParse<Subject=I>, I>(rdr: &mut BufReader<R>) -> HttpResu
_partial => ()
}
match try!(rdr.read_into_buf()) {
0 if rdr.get_buf().len() == 0 => {
0 if rdr.get_buf().is_empty() => {
return Err(HttpIoError(io::Error::new(
io::ErrorKind::ConnectionAborted,
"Connection closed"
Expand Down

0 comments on commit 6b59bd2

Please sign in to comment.