into_string to to_string, from_str to parse

This commit is contained in:
Sean McArthur
2014-12-23 13:09:58 -08:00
parent 691c70a380
commit 79fc40cbce
13 changed files with 42 additions and 42 deletions

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

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

View File

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

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

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

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

View File

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

View File

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

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

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