into_string to to_string, from_str to parse
This commit is contained in:
		| @@ -36,7 +36,7 @@ impl Header for Accept { | ||||
|             match from_utf8(mimes_raw.as_slice()) { | ||||
|                 Ok(mimes_str) => { | ||||
|                     for mime_str in mimes_str.split(',') { | ||||
|                         match from_str(mime_str.trim()) { | ||||
|                         match mime_str.trim().parse() { | ||||
|                             Some(mime) => mimes.push(mime), | ||||
|                             None => return None | ||||
|                         } | ||||
|   | ||||
| @@ -29,9 +29,9 @@ impl<S: Scheme> Header for Authorization<S> { | ||||
|             match (from_utf8(unsafe { raw[].unsafe_get(0)[] }), Scheme::scheme(None::<S>)) { | ||||
|                 (Ok(header), Some(scheme)) | ||||
|                     if header.starts_with(scheme) && header.len() > scheme.len() + 1 => { | ||||
|                     from_str::<S>(header[scheme.len() + 1..]).map(|s| Authorization(s)) | ||||
|                     header[scheme.len() + 1..].parse::<S>().map(|s| Authorization(s)) | ||||
|                 }, | ||||
|                 (Ok(header), None) => from_str::<S>(header).map(|s| Authorization(s)), | ||||
|                 (Ok(header), None) => header.parse::<S>().map(|s| Authorization(s)), | ||||
|                 _ => None | ||||
|             } | ||||
|         } else { | ||||
| @@ -111,11 +111,11 @@ impl FromStr for Basic { | ||||
|                 Ok(text) => { | ||||
|                     let mut parts = text[].split(':'); | ||||
|                     let user = match parts.next() { | ||||
|                         Some(part) => part.into_string(), | ||||
|                         Some(part) => part.to_string(), | ||||
|                         None => return None | ||||
|                     }; | ||||
|                     let password = match parts.next() { | ||||
|                         Some(part) => Some(part.into_string()), | ||||
|                         Some(part) => Some(part.to_string()), | ||||
|                         None => None | ||||
|                     }; | ||||
|                     Some(Basic { | ||||
| @@ -149,7 +149,7 @@ mod tests { | ||||
|     #[test] | ||||
|     fn test_raw_auth() { | ||||
|         let mut headers = Headers::new(); | ||||
|         headers.set(Authorization("foo bar baz".into_string())); | ||||
|         headers.set(Authorization("foo bar baz".to_string())); | ||||
|         assert_eq!(headers.to_string(), "Authorization: foo bar baz\r\n".to_string()); | ||||
|     } | ||||
|  | ||||
| @@ -162,8 +162,8 @@ mod tests { | ||||
|     #[test] | ||||
|     fn test_basic_auth() { | ||||
|         let mut headers = Headers::new(); | ||||
|         headers.set(Authorization(Basic { username: "Aladdin".into_string(), password: Some("open sesame".into_string()) })); | ||||
|         assert_eq!(headers.to_string(), "Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\r\n".into_string()); | ||||
|         headers.set(Authorization(Basic { username: "Aladdin".to_string(), password: Some("open sesame".to_string()) })); | ||||
|         assert_eq!(headers.to_string(), "Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\r\n".to_string()); | ||||
|     } | ||||
|  | ||||
|     #[test] | ||||
|   | ||||
| @@ -110,14 +110,14 @@ impl FromStr for CacheDirective { | ||||
|             "" => None, | ||||
|             _ => match s.find('=') { | ||||
|                 Some(idx) if idx+1 < s.len() => match (s[..idx], s[idx+1..].trim_chars('"')) { | ||||
|                     ("max-age" , secs) => from_str::<uint>(secs).map(MaxAge), | ||||
|                     ("max-stale", secs) => from_str::<uint>(secs).map(MaxStale), | ||||
|                     ("min-fresh", secs) => from_str::<uint>(secs).map(MinFresh), | ||||
|                     ("s-maxage", secs) => from_str::<uint>(secs).map(SMaxAge), | ||||
|                     (left, right) => Some(Extension(left.into_string(), Some(right.into_string()))) | ||||
|                     ("max-age" , secs) => secs.parse().map(MaxAge), | ||||
|                     ("max-stale", secs) => secs.parse().map(MaxStale), | ||||
|                     ("min-fresh", secs) => secs.parse().map(MinFresh), | ||||
|                     ("s-maxage", secs) => secs.parse().map(SMaxAge), | ||||
|                     (left, right) => Some(Extension(left.to_string(), Some(right.to_string()))) | ||||
|                 }, | ||||
|                 Some(_) => None, | ||||
|                 None => Some(Extension(s.into_string(), None)) | ||||
|                 None => Some(Extension(s.to_string(), None)) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| use header::{Header, HeaderFormat}; | ||||
| use std::fmt::{mod, Show}; | ||||
| use std::str::{from_utf8, from_str}; | ||||
| use std::str::from_utf8; | ||||
|  | ||||
| use cookie::Cookie; | ||||
| use cookie::CookieJar; | ||||
| @@ -29,7 +29,7 @@ impl Header for Cookies { | ||||
|             match from_utf8(cookies_raw[]) { | ||||
|                 Ok(cookies_str) => { | ||||
|                     for cookie_str in cookies_str.split(';') { | ||||
|                         match from_str(cookie_str.trim()) { | ||||
|                         match cookie_str.trim().parse() { | ||||
|                             Some(cookie) => cookies.push(cookie), | ||||
|                             None => return None | ||||
|                         } | ||||
|   | ||||
| @@ -55,7 +55,7 @@ impl Header for Etag { | ||||
|                 if check_slice_validity(slice.slice_chars(1, length-1)) { | ||||
|                     return Some(Etag { | ||||
|                         weak: false, | ||||
|                         tag: slice.slice_chars(1, length-1).into_string() | ||||
|                         tag: slice.slice_chars(1, length-1).to_string() | ||||
|                     }); | ||||
|                 } else { | ||||
|                     return None; | ||||
| @@ -66,7 +66,7 @@ impl Header for Etag { | ||||
|                 if check_slice_validity(slice.slice_chars(3, length-1)) { | ||||
|                     return Some(Etag { | ||||
|                         weak: true, | ||||
|                         tag: slice.slice_chars(3, length-1).into_string() | ||||
|                         tag: slice.slice_chars(3, length-1).to_string() | ||||
|                     }); | ||||
|                 } else { | ||||
|                     return None; | ||||
| @@ -100,31 +100,31 @@ mod tests { | ||||
|         etag = Header::parse_header([b"\"foobar\"".to_vec()].as_slice()); | ||||
|         assert_eq!(etag, Some(Etag { | ||||
|             weak: false, | ||||
|             tag: "foobar".into_string() | ||||
|             tag: "foobar".to_string() | ||||
|         })); | ||||
|  | ||||
|         etag = Header::parse_header([b"\"\"".to_vec()].as_slice()); | ||||
|         assert_eq!(etag, Some(Etag { | ||||
|             weak: false, | ||||
|             tag: "".into_string() | ||||
|             tag: "".to_string() | ||||
|         })); | ||||
|  | ||||
|         etag = Header::parse_header([b"W/\"weak-etag\"".to_vec()].as_slice()); | ||||
|         assert_eq!(etag, Some(Etag { | ||||
|             weak: true, | ||||
|             tag: "weak-etag".into_string() | ||||
|             tag: "weak-etag".to_string() | ||||
|         })); | ||||
|  | ||||
|         etag = Header::parse_header([b"W/\"\x65\x62\"".to_vec()].as_slice()); | ||||
|         assert_eq!(etag, Some(Etag { | ||||
|             weak: true, | ||||
|             tag: "\u{0065}\u{0062}".into_string() | ||||
|             tag: "\u{0065}\u{0062}".to_string() | ||||
|         })); | ||||
|  | ||||
|         etag = Header::parse_header([b"W/\"\"".to_vec()].as_slice()); | ||||
|         assert_eq!(etag, Some(Etag { | ||||
|             weak: true, | ||||
|             tag: "".into_string() | ||||
|             tag: "".to_string() | ||||
|         })); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -46,7 +46,7 @@ impl Header for Host { | ||||
|             }; | ||||
|  | ||||
|             let port = match idx { | ||||
|                 Some(idx) => from_str::<u16>(s[].slice_from(idx + 1)), | ||||
|                 Some(idx) => s[].slice_from(idx + 1).parse(), | ||||
|                 None => None | ||||
|             }; | ||||
|  | ||||
| @@ -82,14 +82,14 @@ mod tests { | ||||
|     fn test_host() { | ||||
|         let host = Header::parse_header([b"foo.com".to_vec()].as_slice()); | ||||
|         assert_eq!(host, Some(Host { | ||||
|             hostname: "foo.com".into_string(), | ||||
|             hostname: "foo.com".to_string(), | ||||
|             port: None | ||||
|         })); | ||||
|  | ||||
|  | ||||
|         let host = Header::parse_header([b"foo.com:8080".to_vec()].as_slice()); | ||||
|         assert_eq!(host, Some(Host { | ||||
|             hostname: "foo.com".into_string(), | ||||
|             hostname: "foo.com".to_string(), | ||||
|             port: Some(8080) | ||||
|         })); | ||||
|     } | ||||
|   | ||||
| @@ -25,7 +25,7 @@ impl Header for SetCookie { | ||||
|         for set_cookies_raw in raw.iter() { | ||||
|             match from_utf8(set_cookies_raw[]) { | ||||
|                 Ok(s) if !s.is_empty() => { | ||||
|                     match from_str(s) { | ||||
|                     match s.parse() { | ||||
|                         Some(cookie) => set_cookies.push(cookie), | ||||
|                         None => () | ||||
|                     } | ||||
|   | ||||
| @@ -32,7 +32,7 @@ pub fn from_one_comma_delimited<T: FromStr>(raw: &[u8]) -> Option<Vec<T>> { | ||||
|         Ok(s) => { | ||||
|             Some(s.as_slice() | ||||
|                  .split([',', ' '].as_slice()) | ||||
|                  .filter_map(from_str) | ||||
|                  .filter_map(FromStr::from_str) | ||||
|                  .collect()) | ||||
|         } | ||||
|         Err(_) => None | ||||
|   | ||||
| @@ -620,7 +620,7 @@ mod tests { | ||||
|     fn test_headers_show() { | ||||
|         let mut headers = Headers::new(); | ||||
|         headers.set(ContentLength(15)); | ||||
|         headers.set(Host { hostname: "foo.bar".into_string(), port: None }); | ||||
|         headers.set(Host { hostname: "foo.bar".to_string(), port: None }); | ||||
|  | ||||
|         let s = headers.to_string(); | ||||
|         // hashmap's iterators have arbitrary order, so we must sort first | ||||
|   | ||||
		Reference in New Issue
	
	Block a user