diff --git a/Cargo.toml b/Cargo.toml index 00d0a603..86139a95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,8 @@ typeable = "*" cookie = "*" time = "*" mucell = "*" +log = "*" +rustc-serialize = "*" [dev-dependencies] curl = "*" diff --git a/src/client/mod.rs b/src/client/mod.rs index 57e27883..04bd8ef4 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -381,7 +381,7 @@ mod tests { client.set_redirect_policy(RedirectPolicy::FollowAll); let res = client.get("http://127.0.0.1").send().unwrap(); - assert_eq!(res.headers.get(), Some(&Server("mock3".into_string()))); + assert_eq!(res.headers.get(), Some(&Server("mock3".to_string()))); } #[test] @@ -389,7 +389,7 @@ mod tests { let mut client = Client::with_connector(MockRedirectPolicy); client.set_redirect_policy(RedirectPolicy::FollowNone); let res = client.get("http://127.0.0.1").send().unwrap(); - assert_eq!(res.headers.get(), Some(&Server("mock1".into_string()))); + assert_eq!(res.headers.get(), Some(&Server("mock1".to_string()))); } #[test] @@ -400,7 +400,7 @@ mod tests { let mut client = Client::with_connector(MockRedirectPolicy); client.set_redirect_policy(RedirectPolicy::FollowIf(follow_if)); let res = client.get("http://127.0.0.1").send().unwrap(); - assert_eq!(res.headers.get(), Some(&Server("mock2".into_string()))); + assert_eq!(res.headers.get(), Some(&Server("mock2".to_string()))); } } diff --git a/src/header/common/accept.rs b/src/header/common/accept.rs index 3080ebbd..bfa847ff 100644 --- a/src/header/common/accept.rs +++ b/src/header/common/accept.rs @@ -34,15 +34,15 @@ impl Header for Accept { let mut mimes: Vec = vec![]; for mimes_raw in raw.iter() { match from_utf8(mimes_raw.as_slice()) { - Some(mimes_str) => { + 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 } } }, - None => return None + Err(_) => return None }; } diff --git a/src/header/common/authorization.rs b/src/header/common/authorization.rs index b6708b95..0b953f8f 100644 --- a/src/header/common/authorization.rs +++ b/src/header/common/authorization.rs @@ -27,11 +27,11 @@ impl Header for Authorization { fn parse_header(raw: &[Vec]) -> Option> { if raw.len() == 1 { match (from_utf8(unsafe { raw[].unsafe_get(0)[] }), Scheme::scheme(None::)) { - (Some(header), Some(scheme)) + (Ok(header), Some(scheme)) if header.starts_with(scheme) && header.len() > scheme.len() + 1 => { - from_str::(header[scheme.len() + 1..]).map(|s| Authorization(s)) + header[scheme.len() + 1..].parse::().map(|s| Authorization(s)) }, - (Some(header), None) => from_str::(header).map(|s| Authorization(s)), + (Ok(header), None) => header.parse::().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] diff --git a/src/header/common/cache_control.rs b/src/header/common/cache_control.rs index 1844c82b..83e04b08 100644 --- a/src/header/common/cache_control.rs +++ b/src/header/common/cache_control.rs @@ -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::(secs).map(MaxAge), - ("max-stale", secs) => from_str::(secs).map(MaxStale), - ("min-fresh", secs) => from_str::(secs).map(MinFresh), - ("s-maxage", secs) => from_str::(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)) } } } diff --git a/src/header/common/cookie.rs b/src/header/common/cookie.rs index a4717995..46b53d82 100644 --- a/src/header/common/cookie.rs +++ b/src/header/common/cookie.rs @@ -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; @@ -27,15 +27,15 @@ impl Header for Cookies { let mut cookies = Vec::with_capacity(raw.len()); for cookies_raw in raw.iter() { match from_utf8(cookies_raw[]) { - Some(cookies_str) => { + 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 } } }, - None => return None + Err(_) => return None }; } diff --git a/src/header/common/etag.rs b/src/header/common/etag.rs index 74a355d3..bddbf02e 100644 --- a/src/header/common/etag.rs +++ b/src/header/common/etag.rs @@ -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() })); } diff --git a/src/header/common/host.rs b/src/header/common/host.rs index dd1554e9..3f14d658 100644 --- a/src/header/common/host.rs +++ b/src/header/common/host.rs @@ -46,7 +46,7 @@ impl Header for Host { }; let port = match idx { - Some(idx) => from_str::(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) })); } diff --git a/src/header/common/set_cookie.rs b/src/header/common/set_cookie.rs index aee732d1..faa50f51 100644 --- a/src/header/common/set_cookie.rs +++ b/src/header/common/set_cookie.rs @@ -24,8 +24,8 @@ impl Header for SetCookie { let mut set_cookies = Vec::with_capacity(raw.len()); for set_cookies_raw in raw.iter() { match from_utf8(set_cookies_raw[]) { - Some(s) if !s.is_empty() => { - match from_str(s) { + Ok(s) if !s.is_empty() => { + match s.parse() { Some(cookie) => set_cookies.push(cookie), None => () } diff --git a/src/header/common/util.rs b/src/header/common/util.rs index b6bb4d3c..0d272463 100644 --- a/src/header/common/util.rs +++ b/src/header/common/util.rs @@ -11,8 +11,8 @@ pub fn from_one_raw_str(raw: &[Vec]) -> Option { } // we JUST checked that raw.len() == 1, so raw[0] WILL exist. match from_utf8(unsafe { raw[].unsafe_get(0)[] }) { - Some(s) => FromStr::from_str(s), - None => None + Ok(s) => FromStr::from_str(s), + Err(_) => None } } @@ -29,13 +29,13 @@ pub fn from_comma_delimited(raw: &[Vec]) -> Option> { /// Reads a comma-delimited raw string into a Vec. pub fn from_one_comma_delimited(raw: &[u8]) -> Option> { match from_utf8(raw) { - Some(s) => { + Ok(s) => { Some(s.as_slice() .split([',', ' '].as_slice()) - .filter_map(from_str) + .filter_map(FromStr::from_str) .collect()) } - None => None + Err(_) => None } } diff --git a/src/header/common/vary.rs b/src/header/common/vary.rs index 9b548189..40d4fa60 100644 --- a/src/header/common/vary.rs +++ b/src/header/common/vary.rs @@ -42,7 +42,7 @@ impl HeaderFormat for Vary { #[cfg(test)] mod tests { use super::Vary; - use header::{Header, CaseInsensitive}; + use header::Header; #[test] fn test_vary() { @@ -52,8 +52,8 @@ mod tests { assert_eq!(vary, Some(Vary::Any)); vary = Header::parse_header([b"etag,cookie,allow".to_vec()].as_slice()); - assert_eq!(vary, Some(Vary::Headers(vec![from_str::("eTag").unwrap(), - from_str::("cookIE").unwrap(), - from_str::("AlLOw").unwrap(),]))); + assert_eq!(vary, Some(Vary::Headers(vec!["eTag".parse().unwrap(), + "cookIE".parse().unwrap(), + "AlLOw".parse().unwrap(),]))); } } diff --git a/src/header/mod.rs b/src/header/mod.rs index 01cb3f80..3c6ca29b 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -12,7 +12,7 @@ use std::intrinsics::TypeId; use std::raw::TraitObject; use std::str::{SendStr, FromStr}; use std::collections::HashMap; -use std::collections::hash_map::{Entries, Occupied, Vacant}; +use std::collections::hash_map::{Entries, Entry}; use std::{hash, mem}; use mucell::MuCell; @@ -130,8 +130,8 @@ impl Headers { debug!("raw header: {}={}", name, value[].to_ascii()); let name = CaseInsensitive(Owned(name)); let mut item = match headers.data.entry(name) { - Vacant(entry) => entry.set(MuCell::new(Item::raw(vec![]))), - Occupied(entry) => entry.into_mut() + Entry::Vacant(entry) => entry.set(MuCell::new(Item::raw(vec![]))), + Entry::Occupied(entry) => entry.into_mut() }; match &mut item.borrow_mut().raw { @@ -549,7 +549,7 @@ mod tests { #[test] fn test_accept() { let text_plain = Mime(Text, Plain, vec![]); - let application_vendor = from_str("application/vnd.github.v3.full+json; q=0.5").unwrap(); + let application_vendor = "application/vnd.github.v3.full+json; q=0.5".parse().unwrap(); let accept = Header::parse_header([b"text/plain".to_vec()].as_slice()); assert_eq!(accept, Some(Accept(vec![text_plain.clone()]))); @@ -574,8 +574,8 @@ mod tests { } // we JUST checked that raw.len() == 1, so raw[0] WILL exist. match from_utf8(unsafe { raw.as_slice().unsafe_get(0).as_slice() }) { - Some(s) => FromStr::from_str(s), - None => None + Ok(s) => FromStr::from_str(s), + Err(_) => None }.map(|u| CrazyLength(Some(false), u)) } } @@ -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 diff --git a/src/http.rs b/src/http.rs index b02a09a1..d2809ce5 100644 --- a/src/http.rs +++ b/src/http.rs @@ -4,7 +4,7 @@ use std::cmp::min; use std::fmt; use std::io::{mod, Reader, IoResult, BufWriter}; use std::num::from_u16; -use std::str::{mod, SendStr}; +use std::str::{mod, SendStr, FromStr}; use url::Url; use url::ParseError as UrlError; @@ -260,7 +260,7 @@ impl Writer for HttpWriter { Err(io::IoError { kind: io::ShortWrite(bytes), desc: "EmptyWriter cannot write any bytes", - detail: Some("Cannot include a body with this kind of message".into_string()) + detail: Some("Cannot include a body with this kind of message".to_string()) }) } } @@ -397,7 +397,7 @@ pub fn read_method(stream: &mut R) -> HttpResult { (Some(method), _) => Ok(method), (None, ext) => { // We already checked that the buffer is ASCII - Ok(method::Method::Extension(unsafe { str::from_utf8_unchecked(ext) }.trim().into_string())) + Ok(method::Method::Extension(unsafe { str::from_utf8_unchecked(ext) }.trim().to_string())) }, } } @@ -622,7 +622,7 @@ pub fn read_status(stream: &mut R) -> HttpResult { try!(stream.read_byte()), ]; - let code = match str::from_utf8(code.as_slice()).and_then(from_str::) { + let code = match str::from_utf8(code.as_slice()).ok().and_then(FromStr::from_str) { Some(num) => num, None => return Err(HttpStatusError) }; @@ -662,8 +662,8 @@ pub fn read_status(stream: &mut R) -> HttpResult { } let reason = match str::from_utf8(buf[]) { - Some(s) => s.trim(), - None => return Err(HttpStatusError) + Ok(s) => s.trim(), + Err(_) => return Err(HttpStatusError) }; let reason = match from_u16::(code) { @@ -672,10 +672,10 @@ pub fn read_status(stream: &mut R) -> HttpResult { if phrase == reason { Borrowed(phrase) } else { - Owned(reason.into_string()) + Owned(reason.to_string()) } } - _ => Owned(reason.into_string()) + _ => Owned(reason.to_string()) }, None => return Err(HttpStatusError) }; diff --git a/src/lib.rs b/src/lib.rs index 3e199ce6..7ee41025 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -125,7 +125,7 @@ //! implement `Reader` and can be read to get the data out of a `Response`. //! -extern crate serialize; +extern crate "rustc-serialize" as serialize; extern crate time; extern crate url; extern crate openssl; diff --git a/src/mock.rs b/src/mock.rs index 6f4867fb..db1fe05a 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -62,7 +62,7 @@ impl Writer for MockStream { impl NetworkStream for MockStream { fn peer_name(&mut self) -> IoResult { - Ok(from_str("127.0.0.1:1337").unwrap()) + Ok("127.0.0.1:1337".parse().unwrap()) } } diff --git a/src/server/mod.rs b/src/server/mod.rs index 3f338b2b..e722b410 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -68,7 +68,7 @@ impl, S: NetworkStream, A: NetworkAcceptor> Server); } -impl Handler for fn(Request, Response) { +impl Handler for F where F: Fn(Request, Response), F: Sync + Send { fn handle(&self, req: Request, res: Response) { (*self)(req, res) } diff --git a/src/server/request.rs b/src/server/request.rs index b35efcc5..4a7697cd 100644 --- a/src/server/request.rs +++ b/src/server/request.rs @@ -92,7 +92,7 @@ mod tests { "); let mut req = Request::new(&mut stream, sock!("127.0.0.1:80")).unwrap(); - assert_eq!(req.read_to_string(), Ok("".into_string())); + assert_eq!(req.read_to_string(), Ok("".to_string())); } #[test] @@ -105,7 +105,7 @@ mod tests { "); let mut req = Request::new(&mut stream, sock!("127.0.0.1:80")).unwrap(); - assert_eq!(req.read_to_string(), Ok("".into_string())); + assert_eq!(req.read_to_string(), Ok("".to_string())); } #[test] @@ -118,6 +118,6 @@ mod tests { "); let mut req = Request::new(&mut stream, sock!("127.0.0.1:80")).unwrap(); - assert_eq!(req.read_to_string(), Ok("".into_string())); + assert_eq!(req.read_to_string(), Ok("".to_string())); } }