Merge pull request #206 from hyperium/rustup

Rustup
This commit is contained in:
Sean McArthur
2014-12-23 14:17:53 -08:00
17 changed files with 69 additions and 67 deletions

View File

@@ -19,6 +19,8 @@ typeable = "*"
cookie = "*"
time = "*"
mucell = "*"
log = "*"
rustc-serialize = "*"
[dev-dependencies]
curl = "*"

View File

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

View File

@@ -34,15 +34,15 @@ impl Header for Accept {
let mut mimes: Vec<Mime> = 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
};
}

View File

@@ -27,11 +27,11 @@ 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[].unsafe_get(0)[] }), Scheme::scheme(None::<S>)) {
(Some(header), Some(scheme))
(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))
},
(Some(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]

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -11,8 +11,8 @@ pub fn from_one_raw_str<T: FromStr>(raw: &[Vec<u8>]) -> Option<T> {
}
// 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<T: FromStr>(raw: &[Vec<u8>]) -> Option<Vec<T>> {
/// Reads a comma-delimited raw string into a Vec.
pub fn from_one_comma_delimited<T: FromStr>(raw: &[u8]) -> Option<Vec<T>> {
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
}
}

View File

@@ -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::<CaseInsensitive>("eTag").unwrap(),
from_str::<CaseInsensitive>("cookIE").unwrap(),
from_str::<CaseInsensitive>("AlLOw").unwrap(),])));
assert_eq!(vary, Some(Vary::Headers(vec!["eTag".parse().unwrap(),
"cookIE".parse().unwrap(),
"AlLOw".parse().unwrap(),])));
}
}

View File

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

View File

@@ -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<W: Writer> Writer for HttpWriter<W> {
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<R: Reader>(stream: &mut R) -> HttpResult<method::Method> {
(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<R: Reader>(stream: &mut R) -> HttpResult<RawStatus> {
try!(stream.read_byte()),
];
let code = match str::from_utf8(code.as_slice()).and_then(from_str::<u16>) {
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<R: Reader>(stream: &mut R) -> HttpResult<RawStatus> {
}
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::<StatusCode>(code) {
@@ -672,10 +672,10 @@ pub fn read_status<R: Reader>(stream: &mut R) -> HttpResult<RawStatus> {
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)
};

View File

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

View File

@@ -62,7 +62,7 @@ impl Writer for MockStream {
impl NetworkStream for MockStream {
fn peer_name(&mut self) -> IoResult<SocketAddr> {
Ok(from_str("127.0.0.1:1337").unwrap())
Ok("127.0.0.1:1337".parse().unwrap())
}
}

View File

@@ -68,7 +68,7 @@ impl<L: NetworkListener<S, A>, S: NetworkStream, A: NetworkAcceptor<S>> Server<L
let acceptor = try!(listener.listen());
let mut captured = acceptor.clone();
let guard = Builder::new().name("hyper acceptor".into_string()).spawn(move || {
let guard = Builder::new().name("hyper acceptor".to_string()).spawn(move || {
let handler = Arc::new(handler);
debug!("threads = {}", threads);
let pool = TaskPool::new(threads);
@@ -179,7 +179,7 @@ pub trait Handler: Sync + Send {
fn handle(&self, Request, Response<Fresh>);
}
impl Handler for fn(Request, Response<Fresh>) {
impl<F> Handler for F where F: Fn(Request, Response<Fresh>), F: Sync + Send {
fn handle(&self, req: Request, res: Response<Fresh>) {
(*self)(req, res)
}

View File

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