Update for latest rust
Tracks rust nightly. 7 tests fail -- still finding source
This commit is contained in:
		| @@ -28,7 +28,7 @@ use mime; | ||||
| #[derive(Clone, PartialEq, Show)] | ||||
| pub struct Accept(pub Vec<shared::QualityItem<mime::Mime>>); | ||||
|  | ||||
| deref!(Accept -> Vec<shared::QualityItem<mime::Mime>>); | ||||
| deref!(Accept => Vec<shared::QualityItem<mime::Mime>>); | ||||
|  | ||||
| impl header::Header for Accept { | ||||
|     fn header_name(_: Option<Accept>) -> &'static str { | ||||
| @@ -43,7 +43,7 @@ impl header::Header for Accept { | ||||
|  | ||||
| impl header::HeaderFormat for Accept { | ||||
|     fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         shared::fmt_comma_delimited(fmt, self[]) | ||||
|         shared::fmt_comma_delimited(fmt, &self[]) | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -10,7 +10,7 @@ use header::shared; | ||||
| #[derive(Clone, PartialEq, Show)] | ||||
| pub struct AcceptEncoding(pub Vec<shared::QualityItem<shared::Encoding>>); | ||||
|  | ||||
| deref!(AcceptEncoding -> Vec<shared::QualityItem<shared::Encoding>>); | ||||
| deref!(AcceptEncoding => Vec<shared::QualityItem<shared::Encoding>>); | ||||
|  | ||||
| impl header::Header for AcceptEncoding { | ||||
|     fn header_name(_: Option<AcceptEncoding>) -> &'static str { | ||||
| @@ -24,7 +24,7 @@ impl header::Header for AcceptEncoding { | ||||
|  | ||||
| impl header::HeaderFormat for AcceptEncoding { | ||||
|     fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         shared::fmt_comma_delimited(fmt, self[]) | ||||
|         shared::fmt_comma_delimited(fmt, &self[]) | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -19,7 +19,7 @@ impl header::Header for AccessControlAllowOrigin { | ||||
|  | ||||
|     fn parse_header(raw: &[Vec<u8>]) -> Option<AccessControlAllowOrigin> { | ||||
|         if raw.len() == 1 { | ||||
|             match str::from_utf8(unsafe { raw[].get_unchecked(0)[] }) { | ||||
|             match str::from_utf8(unsafe { &raw[].get_unchecked(0)[] }) { | ||||
|                 Ok(s) => { | ||||
|                     if s == "*" { | ||||
|                         Some(AccessControlAllowOrigin::AllowStar) | ||||
|   | ||||
| @@ -9,7 +9,7 @@ use header::shared::util::{from_comma_delimited, fmt_comma_delimited}; | ||||
| #[derive(Clone, PartialEq, Show)] | ||||
| pub struct Allow(pub Vec<Method>); | ||||
|  | ||||
| deref!(Allow -> Vec<Method>); | ||||
| deref!(Allow => Vec<Method>); | ||||
|  | ||||
| impl Header for Allow { | ||||
|     fn header_name(_: Option<Allow>) -> &'static str { | ||||
| @@ -23,7 +23,7 @@ impl Header for Allow { | ||||
|  | ||||
| impl HeaderFormat for Allow { | ||||
|     fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         fmt_comma_delimited(fmt, self[]) | ||||
|         fmt_comma_delimited(fmt, &self[]) | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -29,7 +29,7 @@ impl<S: Scheme> Header for Authorization<S> { | ||||
|  | ||||
|     fn parse_header(raw: &[Vec<u8>]) -> Option<Authorization<S>> { | ||||
|         if raw.len() == 1 { | ||||
|             match (from_utf8(unsafe { raw[].get_unchecked(0)[] }), Scheme::scheme(None::<S>)) { | ||||
|             match (from_utf8(unsafe { &raw[].get_unchecked(0)[] }), Scheme::scheme(None::<S>)) { | ||||
|                 (Ok(header), Some(scheme)) | ||||
|                     if header.starts_with(scheme) && header.len() > scheme.len() + 1 => { | ||||
|                     header[scheme.len() + 1..].parse::<S>().map(|s| Authorization(s)) | ||||
| @@ -96,7 +96,7 @@ impl Scheme for Basic { | ||||
|         let mut text = self.username.clone(); | ||||
|         text.push(':'); | ||||
|         if let Some(ref pass) = self.password { | ||||
|             text.push_str(pass[]); | ||||
|             text.push_str(&pass[]); | ||||
|         } | ||||
|         text.as_bytes().to_base64(Config { | ||||
|             char_set: Standard, | ||||
| @@ -112,7 +112,7 @@ impl FromStr for Basic { | ||||
|         match s.from_base64() { | ||||
|             Ok(decoded) => match String::from_utf8(decoded) { | ||||
|                 Ok(text) => { | ||||
|                     let mut parts = text[].split(':'); | ||||
|                     let mut parts = &mut text[].split(':'); | ||||
|                     let user = match parts.next() { | ||||
|                         Some(part) => part.to_string(), | ||||
|                         None => return None | ||||
| @@ -127,12 +127,12 @@ impl FromStr for Basic { | ||||
|                     }) | ||||
|                 }, | ||||
|                 Err(e) => { | ||||
|                     debug!("Basic::from_utf8 error={}", e); | ||||
|                     debug!("Basic::from_utf8 error={:?}", e); | ||||
|                     None | ||||
|                 } | ||||
|             }, | ||||
|             Err(e) => { | ||||
|                 debug!("Basic::from_base64 error={}", e); | ||||
|                 debug!("Basic::from_base64 error={:?}", e); | ||||
|                 None | ||||
|             } | ||||
|         } | ||||
| @@ -159,7 +159,7 @@ mod tests { | ||||
|     #[test] | ||||
|     fn test_raw_auth_parse() { | ||||
|         let headers = Headers::from_raw(&mut mem("Authorization: foo bar baz\r\n\r\n")).unwrap(); | ||||
|         assert_eq!(headers.get::<Authorization<String>>().unwrap().0[], "foo bar baz"); | ||||
|         assert_eq!(&headers.get::<Authorization<String>>().unwrap().0[], "foo bar baz"); | ||||
|     } | ||||
|  | ||||
|     #[test] | ||||
| @@ -180,7 +180,7 @@ mod tests { | ||||
|     fn test_basic_auth_parse() { | ||||
|         let headers = Headers::from_raw(&mut mem("Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\r\n\r\n")).unwrap(); | ||||
|         let auth = headers.get::<Authorization<Basic>>().unwrap(); | ||||
|         assert_eq!(auth.0.username[], "Aladdin"); | ||||
|         assert_eq!(&auth.0.username[], "Aladdin"); | ||||
|         assert_eq!(auth.0.password, Some("open sesame".to_string())); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -7,7 +7,7 @@ use header::shared::util::{from_one_comma_delimited, fmt_comma_delimited}; | ||||
| #[derive(PartialEq, Clone, Show)] | ||||
| pub struct CacheControl(pub Vec<CacheDirective>); | ||||
|  | ||||
| deref!(CacheControl -> Vec<CacheDirective>); | ||||
| deref!(CacheControl => Vec<CacheDirective>); | ||||
|  | ||||
| impl Header for CacheControl { | ||||
|     fn header_name(_: Option<CacheControl>) -> &'static str { | ||||
| @@ -16,7 +16,7 @@ impl Header for CacheControl { | ||||
|  | ||||
|     fn parse_header(raw: &[Vec<u8>]) -> Option<CacheControl> { | ||||
|         let directives = raw.iter() | ||||
|             .filter_map(|line| from_one_comma_delimited(line[])) | ||||
|             .filter_map(|line| from_one_comma_delimited(&line[])) | ||||
|             .collect::<Vec<Vec<CacheDirective>>>() | ||||
|             .concat(); | ||||
|         if directives.len() > 0 { | ||||
| @@ -29,7 +29,7 @@ impl Header for CacheControl { | ||||
|  | ||||
| impl HeaderFormat for CacheControl { | ||||
|     fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         fmt_comma_delimited(fmt, self[]) | ||||
|         fmt_comma_delimited(fmt, &self[]) | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -47,11 +47,11 @@ pub enum CacheDirective { | ||||
|  | ||||
|     // request directives | ||||
|     /// "max-age=delta" | ||||
|     MaxAge(uint), | ||||
|     MaxAge(usize), | ||||
|     /// "max-stale=delta" | ||||
|     MaxStale(uint), | ||||
|     MaxStale(usize), | ||||
|     /// "min-fresh=delta" | ||||
|     MinFresh(uint), | ||||
|     MinFresh(usize), | ||||
|  | ||||
|     // response directives | ||||
|     /// "must-revalidate" | ||||
| @@ -63,13 +63,13 @@ pub enum CacheDirective { | ||||
|     /// "proxy-revalidate" | ||||
|     ProxyRevalidate, | ||||
|     /// "s-maxage=delta" | ||||
|     SMaxAge(uint), | ||||
|     SMaxAge(usize), | ||||
|  | ||||
|     /// Extension directives. Optionally include an argument. | ||||
|     Extension(String, Option<String>) | ||||
| } | ||||
|  | ||||
| impl fmt::Show for CacheDirective { | ||||
| impl fmt::String for CacheDirective { | ||||
|     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||
|         use self::CacheDirective::*; | ||||
|         match *self { | ||||
| @@ -88,13 +88,18 @@ impl fmt::Show for CacheDirective { | ||||
|             ProxyRevalidate => "proxy-revalidate", | ||||
|             SMaxAge(secs) => return write!(f, "s-maxage={}", secs), | ||||
|  | ||||
|             Extension(ref name, None) => name[], | ||||
|             Extension(ref name, None) => &name[], | ||||
|             Extension(ref name, Some(ref arg)) => return write!(f, "{}={}", name, arg), | ||||
|  | ||||
|         }.fmt(f) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl fmt::Show for CacheDirective { | ||||
|     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
| 		self.to_string().fmt(fmt) | ||||
| 	} | ||||
| } | ||||
| impl FromStr for CacheDirective { | ||||
|     fn from_str(s: &str) -> Option<CacheDirective> { | ||||
|         use self::CacheDirective::*; | ||||
| @@ -109,7 +114,7 @@ impl FromStr for CacheDirective { | ||||
|             "proxy-revalidate" => Some(ProxyRevalidate), | ||||
|             "" => None, | ||||
|             _ => match s.find('=') { | ||||
|                 Some(idx) if idx+1 < s.len() => match (s[..idx], s[idx+1..].trim_matches('"')) { | ||||
|                 Some(idx) if idx+1 < s.len() => match (&s[..idx], &s[idx+1..].trim_matches('"')) { | ||||
|                     ("max-age" , secs) => secs.parse().map(MaxAge), | ||||
|                     ("max-stale", secs) => secs.parse().map(MaxStale), | ||||
|                     ("min-fresh", secs) => secs.parse().map(MinFresh), | ||||
|   | ||||
| @@ -9,7 +9,7 @@ pub use self::ConnectionOption::{KeepAlive, Close, ConnectionHeader}; | ||||
| #[derive(Clone, PartialEq, Show)] | ||||
| pub struct Connection(pub Vec<ConnectionOption>); | ||||
|  | ||||
| deref!(Connection -> Vec<ConnectionOption>); | ||||
| deref!(Connection => Vec<ConnectionOption>); | ||||
|  | ||||
| /// Values that can be in the `Connection` header. | ||||
| #[derive(Clone, PartialEq)] | ||||
| @@ -39,16 +39,22 @@ impl FromStr for ConnectionOption { | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl fmt::Show for ConnectionOption { | ||||
| impl fmt::String for ConnectionOption { | ||||
|     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         match *self { | ||||
|         write!(fmt, "{}", match *self { | ||||
|             KeepAlive => "keep-alive", | ||||
|             Close => "close", | ||||
|             ConnectionHeader(ref s) => s.as_slice() | ||||
|         }.fmt(fmt) | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl fmt::Show for ConnectionOption { | ||||
|     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
| 		self.to_string().fmt(fmt) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| impl Header for Connection { | ||||
|     fn header_name(_: Option<Connection>) -> &'static str { | ||||
|         "Connection" | ||||
| @@ -62,7 +68,7 @@ impl Header for Connection { | ||||
| impl HeaderFormat for Connection { | ||||
|     fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         let Connection(ref parts) = *self; | ||||
|         fmt_comma_delimited(fmt, parts[]) | ||||
|         fmt_comma_delimited(fmt, &parts[]) | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -5,11 +5,11 @@ use header::shared::util::from_one_raw_str; | ||||
|  | ||||
| /// The `Content-Length` header. | ||||
| /// | ||||
| /// Simply a wrapper around a `uint`. | ||||
| /// Simply a wrapper around a `usize`. | ||||
| #[derive(Copy, Clone, PartialEq, Show)] | ||||
| pub struct ContentLength(pub uint); | ||||
| pub struct ContentLength(pub usize); | ||||
|  | ||||
| deref!(ContentLength -> uint); | ||||
| deref!(ContentLength => usize); | ||||
|  | ||||
| impl Header for ContentLength { | ||||
|     fn header_name(_: Option<ContentLength>) -> &'static str { | ||||
| @@ -32,7 +32,7 @@ impl ContentLength { | ||||
|     /// Returns the wrapped length. | ||||
|     #[deprecated = "use Deref instead"] | ||||
|     #[inline] | ||||
|     pub fn len(&self) -> uint { | ||||
|     pub fn len(&self) -> usize { | ||||
|         **self | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -10,7 +10,7 @@ use mime::Mime; | ||||
| #[derive(Clone, PartialEq, Show)] | ||||
| pub struct ContentType(pub Mime); | ||||
|  | ||||
| deref!(ContentType -> Mime); | ||||
| deref!(ContentType => Mime); | ||||
|  | ||||
| impl Header for ContentType { | ||||
|     fn header_name(_: Option<ContentType>) -> &'static str { | ||||
|   | ||||
| @@ -20,7 +20,7 @@ pub struct Cookies(pub Vec<Cookie>); | ||||
| unsafe impl Send for Cookies {} | ||||
| unsafe impl Sync for Cookies {} | ||||
|  | ||||
| deref!(Cookies -> Vec<Cookie>); | ||||
| deref!(Cookies => Vec<Cookie>); | ||||
|  | ||||
| impl Header for Cookies { | ||||
|     fn header_name(_: Option<Cookies>) -> &'static str { | ||||
| @@ -30,7 +30,7 @@ impl Header for Cookies { | ||||
|     fn parse_header(raw: &[Vec<u8>]) -> Option<Cookies> { | ||||
|         let mut cookies = Vec::with_capacity(raw.len()); | ||||
|         for cookies_raw in raw.iter() { | ||||
|             match from_utf8(cookies_raw[]) { | ||||
|             match from_utf8(&cookies_raw[]) { | ||||
|                 Ok(cookies_str) => { | ||||
|                     for cookie_str in cookies_str.split(';') { | ||||
|                         match cookie_str.trim().parse() { | ||||
| @@ -56,8 +56,8 @@ impl HeaderFormat for Cookies { | ||||
|         let cookies = &self.0; | ||||
|         let last = cookies.len() - 1; | ||||
|         for (i, cookie) in cookies.iter().enumerate() { | ||||
|             try!(cookie.pair().fmt(fmt)); | ||||
|             if i < last { | ||||
|             try!(write!(fmt, "{}", cookie.pair())); | ||||
| 			if i < last { | ||||
|                 try!("; ".fmt(fmt)); | ||||
|             } | ||||
|         } | ||||
| @@ -86,7 +86,7 @@ impl Cookies { | ||||
|  | ||||
| #[test] | ||||
| fn test_parse() { | ||||
|     let h = Header::parse_header([b"foo=bar; baz=quux".to_vec()][]); | ||||
|     let h = Header::parse_header(&[b"foo=bar; baz=quux".to_vec()][]); | ||||
|     let c1 = Cookie::new("foo".to_string(), "bar".to_string()); | ||||
|     let c2 = Cookie::new("baz".to_string(), "quux".to_string()); | ||||
|     assert_eq!(h, Some(Cookies(vec![c1, c2]))); | ||||
| @@ -103,7 +103,7 @@ fn test_fmt() { | ||||
|     let mut headers = Headers::new(); | ||||
|     headers.set(cookies); | ||||
|  | ||||
|     assert_eq!(headers.to_string()[], "Cookie: foo=bar; baz=quux\r\n"); | ||||
|     assert_eq!(&headers.to_string()[], "Cookie: foo=bar; baz=quux\r\n"); | ||||
| } | ||||
|  | ||||
| #[test] | ||||
|   | ||||
| @@ -10,7 +10,7 @@ use header::shared::time::tm_from_str; | ||||
| #[derive(Copy, PartialEq, Clone)] | ||||
| pub struct Date(pub Tm); | ||||
|  | ||||
| deref!(Date -> Tm); | ||||
| deref!(Date => Tm); | ||||
|  | ||||
| impl Header for Date { | ||||
|     fn header_name(_: Option<Date>) -> &'static str { | ||||
|   | ||||
| @@ -38,8 +38,8 @@ impl Header for Etag { | ||||
|  | ||||
|  | ||||
|         from_one_raw_str(raw).and_then(|s: String| { | ||||
|             let length: uint = s.len(); | ||||
|             let slice = s[]; | ||||
|             let length: usize = s.len(); | ||||
|             let slice = &s[]; | ||||
|  | ||||
|             // Early exits: | ||||
|             // 1. The string is empty, or, | ||||
|   | ||||
| @@ -9,7 +9,7 @@ use header::shared::time::tm_from_str; | ||||
| #[derive(Copy, PartialEq, Clone)] | ||||
| pub struct Expires(pub Tm); | ||||
|  | ||||
| deref!(Expires -> Tm); | ||||
| deref!(Expires => Tm); | ||||
|  | ||||
| impl Header for Expires { | ||||
|     fn header_name(_: Option<Expires>) -> &'static str { | ||||
|   | ||||
| @@ -28,7 +28,7 @@ impl Header for Host { | ||||
|             // FIXME: use rust-url to parse this | ||||
|             // https://github.com/servo/rust-url/issues/42 | ||||
|             let idx = { | ||||
|                 let slice = s[]; | ||||
|                 let slice = &s[]; | ||||
|                 if slice.char_at(1) == '[' { | ||||
|                     match slice.rfind(']') { | ||||
|                         Some(idx) => { | ||||
|   | ||||
| @@ -9,7 +9,7 @@ use header::shared::time::tm_from_str; | ||||
| #[derive(Copy, PartialEq, Clone)] | ||||
| pub struct IfModifiedSince(pub Tm); | ||||
|  | ||||
| deref!(IfModifiedSince -> Tm); | ||||
| deref!(IfModifiedSince => Tm); | ||||
|  | ||||
| impl Header for IfModifiedSince { | ||||
|     fn header_name(_: Option<IfModifiedSince>) -> &'static str { | ||||
|   | ||||
| @@ -9,7 +9,7 @@ use header::shared::time::tm_from_str; | ||||
| #[derive(Copy, PartialEq, Clone)] | ||||
| pub struct LastModified(pub Tm); | ||||
|  | ||||
| deref!(LastModified -> Tm); | ||||
| deref!(LastModified => Tm); | ||||
|  | ||||
| impl Header for LastModified { | ||||
|     fn header_name(_: Option<LastModified>) -> &'static str { | ||||
|   | ||||
| @@ -16,7 +16,7 @@ use header::shared::util::from_one_raw_str; | ||||
| #[derive(Clone, PartialEq, Show)] | ||||
| pub struct Location(pub String); | ||||
|  | ||||
| deref!(Location -> String); | ||||
| deref!(Location => String); | ||||
|  | ||||
| impl Header for Location { | ||||
|     fn header_name(_: Option<Location>) -> &'static str { | ||||
|   | ||||
| @@ -42,13 +42,13 @@ macro_rules! bench_header( | ||||
|             fn bench_parse(b: &mut Bencher) { | ||||
|                 let val = $value; | ||||
|                 b.iter(|| { | ||||
|                     let _: $ty = Header::parse_header(val[]).unwrap(); | ||||
|                     let _: $ty = Header::parse_header(&val[]).unwrap(); | ||||
|                 }); | ||||
|             } | ||||
|  | ||||
|             #[bench] | ||||
|             fn bench_format(b: &mut Bencher) { | ||||
|                 let val: $ty = Header::parse_header($value[]).unwrap(); | ||||
|                 let val: $ty = Header::parse_header(&$value[]).unwrap(); | ||||
|                 let fmt = HeaderFormatter(&val); | ||||
|                 b.iter(|| { | ||||
|                     format!("{}", fmt); | ||||
| @@ -59,7 +59,7 @@ macro_rules! bench_header( | ||||
| ); | ||||
|  | ||||
| macro_rules! deref( | ||||
|     ($from:ty -> $to:ty) => { | ||||
|     ($from:ty => $to:ty) => { | ||||
|         impl ::std::ops::Deref for $from { | ||||
|             type Target = $to; | ||||
|  | ||||
|   | ||||
| @@ -8,7 +8,7 @@ use header::shared::util::from_one_raw_str; | ||||
| #[derive(Clone, PartialEq, Show)] | ||||
| pub struct Server(pub String); | ||||
|  | ||||
| deref!(Server -> String); | ||||
| deref!(Server => String); | ||||
|  | ||||
| impl Header for Server { | ||||
|     fn header_name(_: Option<Server>) -> &'static str { | ||||
|   | ||||
| @@ -17,7 +17,7 @@ pub struct SetCookie(pub Vec<Cookie>); | ||||
| unsafe impl Send for SetCookie {} | ||||
| unsafe impl Sync for SetCookie {} | ||||
|  | ||||
| deref!(SetCookie -> Vec<Cookie>); | ||||
| deref!(SetCookie => Vec<Cookie>); | ||||
|  | ||||
| impl Header for SetCookie { | ||||
|     fn header_name(_: Option<SetCookie>) -> &'static str { | ||||
| @@ -27,7 +27,7 @@ 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[]) { | ||||
|             match from_utf8(&set_cookies_raw[]) { | ||||
|                 Ok(s) if !s.is_empty() => { | ||||
|                     match s.parse() { | ||||
|                         Some(cookie) => set_cookies.push(cookie), | ||||
| @@ -80,7 +80,7 @@ impl SetCookie { | ||||
|  | ||||
| #[test] | ||||
| fn test_parse() { | ||||
|     let h = Header::parse_header([b"foo=bar; HttpOnly".to_vec()][]); | ||||
|     let h = Header::parse_header(&[b"foo=bar; HttpOnly".to_vec()][]); | ||||
|     let mut c1 = Cookie::new("foo".to_string(), "bar".to_string()); | ||||
|     c1.httponly = true; | ||||
|  | ||||
| @@ -98,7 +98,7 @@ fn test_fmt() { | ||||
|     let mut headers = Headers::new(); | ||||
|     headers.set(cookies); | ||||
|  | ||||
|     assert_eq!(headers.to_string()[], "Set-Cookie: foo=bar; HttpOnly; Path=/p\r\nSet-Cookie: baz=quux; Path=/\r\n"); | ||||
|     assert_eq!(&headers.to_string()[], "Set-Cookie: foo=bar; HttpOnly; Path=/p\r\nSet-Cookie: baz=quux; Path=/\r\n"); | ||||
| } | ||||
|  | ||||
| #[test] | ||||
|   | ||||
| @@ -21,7 +21,7 @@ use self::Encoding::{Chunked, Gzip, Deflate, Compress, EncodingExt}; | ||||
| #[derive(Clone, PartialEq, Show)] | ||||
| pub struct TransferEncoding(pub Vec<Encoding>); | ||||
|  | ||||
| deref!(TransferEncoding -> Vec<Encoding>); | ||||
| deref!(TransferEncoding => Vec<Encoding>); | ||||
|  | ||||
| /// A value to be used with the `Transfer-Encoding` header. | ||||
| /// | ||||
| @@ -47,18 +47,24 @@ pub enum Encoding { | ||||
|     EncodingExt(String) | ||||
| } | ||||
|  | ||||
| impl fmt::Show for Encoding { | ||||
| impl fmt::String for Encoding { | ||||
|     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         match *self { | ||||
|         write!(fmt, "{}", match *self { | ||||
|             Chunked => "chunked", | ||||
|             Gzip => "gzip", | ||||
|             Deflate => "deflate", | ||||
|             Compress => "compress", | ||||
|             EncodingExt(ref s) => s.as_slice() | ||||
|         }.fmt(fmt) | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl fmt::Show for Encoding { | ||||
|     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
| 		self.to_string().fmt(fmt) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| impl FromStr for Encoding { | ||||
|     fn from_str(s: &str) -> Option<Encoding> { | ||||
|         match s { | ||||
| @@ -83,7 +89,7 @@ impl Header for TransferEncoding { | ||||
|  | ||||
| impl HeaderFormat for TransferEncoding { | ||||
|     fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         fmt_comma_delimited(fmt, self[]) | ||||
|         fmt_comma_delimited(fmt, &self[]) | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -9,7 +9,7 @@ use self::Protocol::{WebSocket, ProtocolExt}; | ||||
| #[derive(Clone, PartialEq, Show)] | ||||
| pub struct Upgrade(pub Vec<Protocol>); | ||||
|  | ||||
| deref!(Upgrade -> Vec<Protocol>); | ||||
| deref!(Upgrade => Vec<Protocol>); | ||||
|  | ||||
| /// Protocol values that can appear in the Upgrade header. | ||||
| #[derive(Clone, PartialEq)] | ||||
| @@ -29,12 +29,18 @@ impl FromStr for Protocol { | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl fmt::Show for Protocol { | ||||
| impl fmt::String for Protocol { | ||||
|     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         match *self { | ||||
|         write!(fmt, "{}", match *self { | ||||
|             WebSocket => "websocket", | ||||
|             ProtocolExt(ref s) => s.as_slice() | ||||
|         }.fmt(fmt) | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl fmt::Show for Protocol { | ||||
|     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         self.to_string().fmt(fmt) | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -51,7 +57,7 @@ impl Header for Upgrade { | ||||
| impl HeaderFormat for Upgrade { | ||||
|     fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         let Upgrade(ref parts) = *self; | ||||
|         fmt_comma_delimited(fmt, parts[]) | ||||
|         fmt_comma_delimited(fmt, &parts[]) | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -8,7 +8,7 @@ use header::shared::util::from_one_raw_str; | ||||
| #[derive(Clone, PartialEq, Show)] | ||||
| pub struct UserAgent(pub String); | ||||
|  | ||||
| deref!(UserAgent -> String); | ||||
| deref!(UserAgent => String); | ||||
|  | ||||
| impl Header for UserAgent { | ||||
|     fn header_name(_: Option<UserAgent>) -> &'static str { | ||||
|   | ||||
| @@ -20,7 +20,7 @@ impl Header for Vary { | ||||
|  | ||||
|     fn parse_header(raw: &[Vec<u8>]) -> Option<Vary> { | ||||
|         from_one_raw_str(raw).and_then(|s: String| { | ||||
|             let slice = s[]; | ||||
|             let slice = &s[]; | ||||
|             match slice { | ||||
|                 "" => None, | ||||
|                 "*" => Some(Vary::Any), | ||||
| @@ -34,7 +34,7 @@ impl HeaderFormat for Vary { | ||||
|     fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         match *self { | ||||
|             Vary::Any => { write!(fmt, "*") } | ||||
|             Vary::Headers(ref fields) => { fmt_comma_delimited(fmt, fields[]) } | ||||
|             Vary::Headers(ref fields) => { fmt_comma_delimited(fmt, &fields[]) } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -134,15 +134,15 @@ impl Headers { | ||||
|         loop { | ||||
|             match try!(http::read_header(rdr)) { | ||||
|                 Some((name, value)) => { | ||||
|                     debug!("raw header: {}={}", name, value[]); | ||||
|                     debug!("raw header: {:?}={:?}", name, &value[]); | ||||
|                     let name = CaseInsensitive(Owned(name)); | ||||
|                     let mut item = match headers.data.entry(&name) { | ||||
|                     let mut item = match headers.data.entry(name) { | ||||
|                         Entry::Vacant(entry) => entry.insert(MuCell::new(Item::raw(vec![]))), | ||||
|                         Entry::Occupied(entry) => entry.into_mut() | ||||
|                     }; | ||||
|  | ||||
|                     match &mut item.borrow_mut().raw { | ||||
|                         &Some(ref mut raw) => raw.push(value), | ||||
|                         &mut Some(ref mut raw) => raw.push(value), | ||||
|                         // Unreachable | ||||
|                         _ => {} | ||||
|                     }; | ||||
| @@ -178,7 +178,7 @@ impl Headers { | ||||
|             .get(&CaseInsensitive(Borrowed(unsafe { mem::transmute::<&str, &str>(name) }))) | ||||
|             .and_then(|item| { | ||||
|                 if let Some(ref raw) = item.borrow().raw { | ||||
|                     return unsafe { mem::transmute(Some(raw[])) }; | ||||
|                     return unsafe { mem::transmute(Some(&raw[])) }; | ||||
|                 } | ||||
|  | ||||
|                 let worked = item.try_mutate(|item| { | ||||
| @@ -189,7 +189,7 @@ impl Headers { | ||||
|  | ||||
|                 let item = item.borrow(); | ||||
|                 let raw = item.raw.as_ref().unwrap(); | ||||
|                 unsafe { mem::transmute(Some(raw[])) } | ||||
|                 unsafe { mem::transmute(Some(&raw[])) } | ||||
|             }) | ||||
|     } | ||||
|  | ||||
| @@ -258,7 +258,7 @@ impl Headers { | ||||
|     } | ||||
|  | ||||
|     /// Returns the number of headers in the map. | ||||
|     pub fn len(&self) -> uint { | ||||
|     pub fn len(&self) -> usize { | ||||
|         self.data.len() | ||||
|     } | ||||
|  | ||||
| @@ -268,7 +268,7 @@ impl Headers { | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl fmt::Show for Headers { | ||||
| impl fmt::String for Headers { | ||||
|     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         for header in self.iter() { | ||||
|             try!(write!(fmt, "{}{}", header, LineEnding)); | ||||
| @@ -277,6 +277,12 @@ impl fmt::Show for Headers { | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl fmt::Show for Headers { | ||||
|     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         self.to_string().fmt(fmt) | ||||
|     } | ||||
| } | ||||
|  | ||||
| /// An `Iterator` over the fields in a `Headers` map. | ||||
| pub struct HeadersItems<'a> { | ||||
|     inner: Iter<'a, CaseInsensitive, MuCell<Item>> | ||||
| @@ -326,12 +332,18 @@ impl<'a> HeaderView<'a> { | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl<'a> fmt::Show for HeaderView<'a> { | ||||
| impl<'a> fmt::String for HeaderView<'a> { | ||||
|     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||
|         write!(f, "{}: {}", self.0, *self.1.borrow()) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl<'a> fmt::Show for HeaderView<'a> { | ||||
|     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         self.to_string().fmt(fmt) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl<'a> Extend<HeaderView<'a>> for Headers { | ||||
|     fn extend<I: Iterator<Item=HeaderView<'a>>>(&mut self, mut iter: I) { | ||||
|         for header in iter { | ||||
| @@ -375,7 +387,7 @@ fn get_or_parse<H: Header + HeaderFormat>(item: &MuCell<Item>) -> Option<&MuCell | ||||
|     match item.borrow().typed { | ||||
|         Some(ref typed) if typed.is::<H>() => return Some(item), | ||||
|         Some(ref typed) => { | ||||
|             warn!("attempted to access {} as wrong type", typed); | ||||
|             warn!("attempted to access {:?} as wrong type", typed); | ||||
|             return None; | ||||
|         } | ||||
|         _ => () | ||||
| @@ -394,7 +406,7 @@ fn get_or_parse_mut<H: Header + HeaderFormat>(item: &mut MuCell<Item>) -> Option | ||||
|     let is_correct_type = match item.borrow().typed { | ||||
|         Some(ref typed) if typed.is::<H>() => Some(true), | ||||
|         Some(ref typed) => { | ||||
|             warn!("attempted to access {} as wrong type", typed); | ||||
|             warn!("attempted to access {:?} as wrong type", typed); | ||||
|             Some(false) | ||||
|         } | ||||
|         _ => None | ||||
| @@ -416,7 +428,7 @@ fn get_or_parse_mut<H: Header + HeaderFormat>(item: &mut MuCell<Item>) -> Option | ||||
|  | ||||
| fn parse<H: Header + HeaderFormat>(item: &mut Item) { | ||||
|     item.typed = match item.raw { | ||||
|         Some(ref raw) => match Header::parse_header(raw[]) { | ||||
|         Some(ref raw) => match Header::parse_header(&raw[]) { | ||||
|             Some::<H>(h) => Some(box h as Box<HeaderFormat + Send + Sync>), | ||||
|             None => None | ||||
|         }, | ||||
| @@ -432,17 +444,17 @@ unsafe fn downcast_mut<H: Header + HeaderFormat>(item: &mut Item) -> &mut H { | ||||
|     item.typed.as_mut().expect("item.typed must be set").downcast_mut_unchecked() | ||||
| } | ||||
|  | ||||
| impl fmt::Show for Item { | ||||
| impl fmt::String for Item { | ||||
|     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         match self.typed { | ||||
|             Some(ref h) => h.fmt_header(fmt), | ||||
|             None => match self.raw { | ||||
|                 Some(ref raw) => { | ||||
|                     for part in raw.iter() { | ||||
|                         match from_utf8(part[]) { | ||||
|                         match from_utf8(&part[]) { | ||||
|                             Ok(s) => try!(fmt.write_str(s)), | ||||
|                             Err(e) => { | ||||
|                                 error!("raw header value is not utf8. header={}, error={}", part[], e); | ||||
|                                 error!("raw header value is not utf8. header={:?}, error={:?}", &part[], e); | ||||
|                                 return Err(fmt::Error); | ||||
|                             } | ||||
|                         } | ||||
| @@ -455,12 +467,24 @@ impl fmt::Show for Item { | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl fmt::Show for Box<HeaderFormat + Send + Sync> { | ||||
| impl<'a> fmt::Show for Item { | ||||
|     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         self.to_string().fmt(fmt) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl fmt::String for Box<HeaderFormat + Send + Sync> { | ||||
|     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         (**self).fmt_header(fmt) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl fmt::Show for Box<HeaderFormat + Send + Sync> { | ||||
|     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         self.to_string().fmt(fmt) | ||||
|     } | ||||
| } | ||||
|  | ||||
| /// Case-insensitive string. | ||||
| pub struct CaseInsensitive(CowString<'static>); | ||||
|  | ||||
| @@ -484,9 +508,15 @@ impl Str for CaseInsensitive { | ||||
|  | ||||
| } | ||||
|  | ||||
| impl fmt::String for CaseInsensitive { | ||||
|     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         write!(fmt, "{}", self.as_slice()) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl fmt::Show for CaseInsensitive { | ||||
|     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         self.as_slice().fmt(fmt) | ||||
|         self.to_string().fmt(fmt) | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -498,7 +528,7 @@ impl PartialEq for CaseInsensitive { | ||||
|  | ||||
| impl Eq for CaseInsensitive {} | ||||
|  | ||||
| impl<H: hash::Writer> hash::Hash<H> for CaseInsensitive { | ||||
| impl<H: hash::Writer + hash::Hasher> hash::Hash<H> for CaseInsensitive { | ||||
|     #[inline] | ||||
|     fn hash(&self, hasher: &mut H) { | ||||
|         for b in self.as_slice().bytes() { | ||||
| @@ -514,6 +544,12 @@ impl<H: hash::Writer> hash::Hash<H> for CaseInsensitive { | ||||
| /// outgoing TcpStream. | ||||
| pub struct HeaderFormatter<'a, H: HeaderFormat>(pub &'a H); | ||||
|  | ||||
| impl<'a, H: HeaderFormat> fmt::String for HeaderFormatter<'a, H> { | ||||
|     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||
|         self.0.fmt_header(f) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl<'a, H: HeaderFormat> Show for HeaderFormatter<'a, H> { | ||||
|     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||
|         self.0.fmt_header(f) | ||||
| @@ -525,7 +561,7 @@ mod tests { | ||||
|     use std::io::MemReader; | ||||
|     use std::fmt; | ||||
|     use std::borrow::Cow::Borrowed; | ||||
|     use std::hash::sip::hash; | ||||
|     use std::hash::{SipHasher, hash}; | ||||
|     use mime::Mime; | ||||
|     use mime::TopLevel::Text; | ||||
|     use mime::SubLevel::Plain; | ||||
| @@ -546,7 +582,7 @@ mod tests { | ||||
|         let b = CaseInsensitive(Borrowed("FOOBAR")); | ||||
|  | ||||
|         assert_eq!(a, b); | ||||
|         assert_eq!(hash(&a), hash(&b)); | ||||
|         assert_eq!(hash::<_, SipHasher>(&a), hash::<_, SipHasher>(&b)); | ||||
|     } | ||||
|  | ||||
|     #[test] | ||||
| @@ -574,7 +610,7 @@ mod tests { | ||||
|     } | ||||
|  | ||||
|     #[derive(Clone, Show)] | ||||
|     struct CrazyLength(Option<bool>, uint); | ||||
|     struct CrazyLength(Option<bool>, usize); | ||||
|  | ||||
|     impl Header for CrazyLength { | ||||
|         fn header_name(_: Option<CrazyLength>) -> &'static str { | ||||
| @@ -588,7 +624,7 @@ mod tests { | ||||
|                 return None; | ||||
|             } | ||||
|             // we JUST checked that raw.len() == 1, so raw[0] WILL exist. | ||||
|             match from_utf8(unsafe { raw[].get_unchecked(0)[] }) { | ||||
|             match from_utf8(unsafe { &raw[].get_unchecked(0)[] }) { | ||||
|                 Ok(s) => FromStr::from_str(s), | ||||
|                 Err(_) => None | ||||
|             }.map(|u| CrazyLength(Some(false), u)) | ||||
| @@ -598,7 +634,7 @@ mod tests { | ||||
|     impl HeaderFormat for CrazyLength { | ||||
|         fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|             let CrazyLength(ref opt, ref value) = *self; | ||||
|             write!(fmt, "{}, {}", opt, value) | ||||
|             write!(fmt, "{:?}, {:?}", opt, value) | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -649,7 +685,7 @@ mod tests { | ||||
|         let mut pieces = s[].split_str("\r\n").collect::<Vec<&str>>(); | ||||
|         pieces.sort(); | ||||
|         let s = pieces.into_iter().rev().collect::<Vec<&str>>().connect("\r\n"); | ||||
|         assert_eq!(s[], "Host: foo.bar\r\nContent-Length: 15\r\n"); | ||||
|         assert_eq!(&s[], "Host: foo.bar\r\nContent-Length: 15\r\n"); | ||||
|     } | ||||
|  | ||||
|     #[test] | ||||
| @@ -664,7 +700,7 @@ mod tests { | ||||
|         let mut headers = Headers::new(); | ||||
|         headers.set(ContentLength(10)); | ||||
|         headers.set_raw("content-LENGTH", vec![b"20".to_vec()]); | ||||
|         assert_eq!(headers.get_raw("Content-length").unwrap(), [b"20".to_vec()][]); | ||||
|         assert_eq!(headers.get_raw("Content-length").unwrap(), &[b"20".to_vec()][]); | ||||
|         assert_eq!(headers.get(), Some(&ContentLength(20))); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -23,18 +23,24 @@ pub enum Encoding { | ||||
|     EncodingExt(String) | ||||
| } | ||||
|  | ||||
| impl fmt::Show for Encoding { | ||||
| impl fmt::String for Encoding { | ||||
|     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         match *self { | ||||
|         write!(fmt, "{}", match *self { | ||||
|             Chunked => "chunked", | ||||
|             Gzip => "gzip", | ||||
|             Deflate => "deflate", | ||||
|             Compress => "compress", | ||||
|             Identity => "identity", | ||||
|             EncodingExt(ref s) => s.as_slice() | ||||
|             }.fmt(fmt) | ||||
|         } | ||||
|     } | ||||
|         }) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| impl fmt::Show for Encoding { | ||||
|     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
| 		self.to_string().fmt(fmt) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| impl str::FromStr for Encoding { | ||||
|     fn from_str(s: &str) -> Option<Encoding> { | ||||
|   | ||||
| @@ -26,7 +26,13 @@ impl<T> QualityItem<T> { | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl<T: fmt::Show> fmt::Show for QualityItem<T> { | ||||
| impl<T: fmt::String> fmt::String for QualityItem<T> { | ||||
|     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||
|         write!(f, "{}; q={}", self.item, format!("{:.3}", self.quality).trim_right_matches(['0', '.'].as_slice())) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl<T: fmt::String> fmt::Show for QualityItem<T> { | ||||
|     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||
|         write!(f, "{}; q={}", self.item, format!("{:.3}", self.quality).trim_right_matches(['0', '.'].as_slice())) | ||||
|     } | ||||
|   | ||||
| @@ -9,7 +9,7 @@ pub fn from_one_raw_str<T: str::FromStr>(raw: &[Vec<u8>]) -> Option<T> { | ||||
|         return None; | ||||
|     } | ||||
|     // we JUST checked that raw.len() == 1, so raw[0] WILL exist. | ||||
|     match str::from_utf8(raw[0][]) { | ||||
|     match str::from_utf8(&raw[0][]) { | ||||
|         Ok(s) => str::FromStr::from_str(s), | ||||
|         Err(_) => None | ||||
|     } | ||||
| @@ -22,7 +22,7 @@ pub fn from_comma_delimited<T: str::FromStr>(raw: &[Vec<u8>]) -> Option<Vec<T>> | ||||
|         return None; | ||||
|     } | ||||
|     // we JUST checked that raw.len() == 1, so raw[0] WILL exist. | ||||
|     from_one_comma_delimited(raw[0][]) | ||||
|     from_one_comma_delimited(&raw[0][]) | ||||
| } | ||||
|  | ||||
| /// Reads a comma-delimited raw string into a Vec. | ||||
| @@ -40,7 +40,7 @@ pub fn from_one_comma_delimited<T: str::FromStr>(raw: &[u8]) -> Option<Vec<T>> { | ||||
| } | ||||
|  | ||||
| /// Format an array into a comma-delimited string. | ||||
| pub fn fmt_comma_delimited<T: fmt::Show>(fmt: &mut fmt::Formatter, parts: &[T]) -> fmt::Result { | ||||
| pub fn fmt_comma_delimited<T: fmt::String>(fmt: &mut fmt::Formatter, parts: &[T]) -> fmt::Result { | ||||
|     let last = parts.len() - 1; | ||||
|     for (i, part) in parts.iter().enumerate() { | ||||
|         try!(write!(fmt, "{}", part)); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user