refactor(hyper): Fix a few nits

This commit is contained in:
Pyfisch
2015-05-01 11:57:25 +02:00
parent 92ee51acdb
commit 6b59bd28b7
8 changed files with 18 additions and 34 deletions

View File

@@ -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)
}
}
}

View File

@@ -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)
}
}
@@ -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)
}
}
@@ -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()] });

View File

@@ -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

View File

@@ -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)),
}

View File

@@ -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() {