perf(all): replace &str.to_string() with .to_owned()
This commit is contained in:
@@ -40,7 +40,7 @@ header! {
|
||||
// vec![b"audio/*; q=0.2, audio/basic"],
|
||||
// Some(HeaderField(vec![
|
||||
// QualityItem::new(Mime(TopLevel::Audio, SubLevel::Star, vec![]), Quality(200)),
|
||||
// qitem(Mime(TopLevel::Audio, SubLevel::Ext("basic".to_string()), vec![])),
|
||||
// qitem(Mime(TopLevel::Audio, SubLevel::Ext("basic".to_owned()), vec![])),
|
||||
// ])));
|
||||
test_header!(
|
||||
test2,
|
||||
@@ -49,9 +49,9 @@ header! {
|
||||
QualityItem::new(Mime(TopLevel::Text, SubLevel::Plain, vec![]), Quality(500)),
|
||||
qitem(Mime(TopLevel::Text, SubLevel::Html, vec![])),
|
||||
QualityItem::new(
|
||||
Mime(TopLevel::Text, SubLevel::Ext("x-dvi".to_string()), vec![]),
|
||||
Mime(TopLevel::Text, SubLevel::Ext("x-dvi".to_owned()), vec![]),
|
||||
Quality(800)),
|
||||
qitem(Mime(TopLevel::Text, SubLevel::Ext("x-c".to_string()), vec![])),
|
||||
qitem(Mime(TopLevel::Text, SubLevel::Ext("x-c".to_owned()), vec![])),
|
||||
])));
|
||||
// Custom tests
|
||||
test_header!(
|
||||
|
||||
@@ -26,9 +26,9 @@ header! {
|
||||
test_header!(
|
||||
test2, vec![b"en-us, en; q=0.5, fr"],
|
||||
Some(AcceptLanguage(vec![
|
||||
qitem(Language {primary: "en".to_string(), sub: Some("us".to_string())}),
|
||||
QualityItem::new(Language{primary: "en".to_string(), sub: None}, Quality(500)),
|
||||
qitem(Language {primary: "fr".to_string(), sub: None}),
|
||||
qitem(Language {primary: "en".to_owned(), sub: Some("us".to_owned())}),
|
||||
QualityItem::new(Language{primary: "en".to_owned(), sub: None}, Quality(500)),
|
||||
qitem(Language {primary: "fr".to_owned(), sub: None}),
|
||||
])));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ impl FromStr for RangeUnit {
|
||||
"bytes" => Ok(RangeUnit::Bytes),
|
||||
"none" => Ok(RangeUnit::None),
|
||||
// FIXME: Check if s is really a Token
|
||||
_ => Ok(RangeUnit::Unregistered(s.to_string())),
|
||||
_ => Ok(RangeUnit::Unregistered(s.to_owned())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ header! {
|
||||
Method::Trace,
|
||||
Method::Connect,
|
||||
Method::Patch,
|
||||
Method::Extension("fOObAr".to_string())])));
|
||||
Method::Extension("fOObAr".to_owned())])));
|
||||
test_header!(
|
||||
test3,
|
||||
vec![b""],
|
||||
|
||||
@@ -128,11 +128,11 @@ impl FromStr for Basic {
|
||||
Ok(text) => {
|
||||
let mut parts = &mut text.split(':');
|
||||
let user = match parts.next() {
|
||||
Some(part) => part.to_string(),
|
||||
Some(part) => part.to_owned(),
|
||||
None => return Err(())
|
||||
};
|
||||
let password = match parts.next() {
|
||||
Some(part) => Some(part.to_string()),
|
||||
Some(part) => Some(part.to_owned()),
|
||||
None => None
|
||||
};
|
||||
Ok(Basic {
|
||||
@@ -161,8 +161,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_raw_auth() {
|
||||
let mut headers = Headers::new();
|
||||
headers.set(Authorization("foo bar baz".to_string()));
|
||||
assert_eq!(headers.to_string(), "Authorization: foo bar baz\r\n".to_string());
|
||||
headers.set(Authorization("foo bar baz".to_owned()));
|
||||
assert_eq!(headers.to_string(), "Authorization: foo bar baz\r\n".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -176,17 +176,17 @@ mod tests {
|
||||
fn test_basic_auth() {
|
||||
let mut headers = Headers::new();
|
||||
headers.set(Authorization(
|
||||
Basic { username: "Aladdin".to_string(), password: Some("open sesame".to_string()) }));
|
||||
Basic { username: "Aladdin".to_owned(), password: Some("open sesame".to_owned()) }));
|
||||
assert_eq!(
|
||||
headers.to_string(),
|
||||
"Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\r\n".to_string());
|
||||
"Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\r\n".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_basic_auth_no_password() {
|
||||
let mut headers = Headers::new();
|
||||
headers.set(Authorization(Basic { username: "Aladdin".to_string(), password: None }));
|
||||
assert_eq!(headers.to_string(), "Authorization: Basic QWxhZGRpbjo=\r\n".to_string());
|
||||
headers.set(Authorization(Basic { username: "Aladdin".to_owned(), password: None }));
|
||||
assert_eq!(headers.to_string(), "Authorization: Basic QWxhZGRpbjo=\r\n".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -194,7 +194,7 @@ mod tests {
|
||||
let auth: Authorization<Basic> = Header::parse_header(
|
||||
&[b"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==".to_vec()]).unwrap();
|
||||
assert_eq!(auth.0.username, "Aladdin");
|
||||
assert_eq!(auth.0.password, Some("open sesame".to_string()));
|
||||
assert_eq!(auth.0.password, Some("open sesame".to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -202,7 +202,7 @@ mod tests {
|
||||
let auth: Authorization<Basic> = Header::parse_header(
|
||||
&[b"Basic QWxhZGRpbjo=".to_vec()]).unwrap();
|
||||
assert_eq!(auth.0.username, "Aladdin");
|
||||
assert_eq!(auth.0.password, Some("".to_string()));
|
||||
assert_eq!(auth.0.password, Some("".to_owned()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -126,15 +126,15 @@ impl FromStr for CacheDirective {
|
||||
"proxy-revalidate" => Ok(ProxyRevalidate),
|
||||
"" => Err(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).map_err(|x| Some(x)),
|
||||
("max-stale", secs) => secs.parse().map(MaxStale).map_err(|x| Some(x)),
|
||||
("min-fresh", secs) => secs.parse().map(MinFresh).map_err(|x| Some(x)),
|
||||
("s-maxage", secs) => secs.parse().map(SMaxAge).map_err(|x| Some(x)),
|
||||
(left, right) => Ok(Extension(left.to_string(), Some(right.to_string())))
|
||||
(left, right) => Ok(Extension(left.to_owned(), Some(right.to_owned())))
|
||||
},
|
||||
Some(_) => Err(None),
|
||||
None => Ok(Extension(s.to_string(), None))
|
||||
None => Ok(Extension(s.to_owned(), None))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -169,8 +169,8 @@ mod tests {
|
||||
fn test_parse_extension() {
|
||||
let cache = Header::parse_header(&[b"foo, bar=baz".to_vec()]);
|
||||
assert_eq!(cache, Some(CacheControl(vec![
|
||||
CacheDirective::Extension("foo".to_string(), None),
|
||||
CacheDirective::Extension("bar".to_string(), Some("baz".to_string()))])))
|
||||
CacheDirective::Extension("foo".to_owned(), None),
|
||||
CacheDirective::Extension("bar".to_owned(), Some("baz".to_owned()))])))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -28,7 +28,7 @@ impl FromStr for ConnectionOption {
|
||||
match s {
|
||||
"keep-alive" => Ok(KeepAlive),
|
||||
"close" => Ok(Close),
|
||||
s => Ok(ConnectionHeader(UniCase(s.to_string())))
|
||||
s => Ok(ConnectionHeader(UniCase(s.to_owned())))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ header! {
|
||||
Some(HeaderField(Mime(
|
||||
TopLevel::Text,
|
||||
SubLevel::Html,
|
||||
vec![(Attr::Charset, Value::Ext("iso-8859-4".to_string()))]))));
|
||||
vec![(Attr::Charset, Value::Ext("iso-8859-4".to_owned()))]))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,8 +86,8 @@ impl Cookie {
|
||||
#[test]
|
||||
fn test_parse() {
|
||||
let h = Header::parse_header(&[b"foo=bar; baz=quux".to_vec()][..]);
|
||||
let c1 = CookiePair::new("foo".to_string(), "bar".to_string());
|
||||
let c2 = CookiePair::new("baz".to_string(), "quux".to_string());
|
||||
let c1 = CookiePair::new("foo".to_owned(), "bar".to_owned());
|
||||
let c2 = CookiePair::new("baz".to_owned(), "quux".to_owned());
|
||||
assert_eq!(h, Some(Cookie(vec![c1, c2])));
|
||||
}
|
||||
|
||||
@@ -95,12 +95,12 @@ fn test_parse() {
|
||||
fn test_fmt() {
|
||||
use header::Headers;
|
||||
|
||||
let mut cookie_pair = CookiePair::new("foo".to_string(), "bar".to_string());
|
||||
let mut cookie_pair = CookiePair::new("foo".to_owned(), "bar".to_owned());
|
||||
cookie_pair.httponly = true;
|
||||
cookie_pair.path = Some("/p".to_string());
|
||||
cookie_pair.path = Some("/p".to_owned());
|
||||
let cookie_header = Cookie(vec![
|
||||
cookie_pair,
|
||||
CookiePair::new("baz".to_string(),"quux".to_string())]);
|
||||
CookiePair::new("baz".to_owned(),"quux".to_owned())]);
|
||||
let mut headers = Headers::new();
|
||||
headers.set(cookie_header);
|
||||
|
||||
@@ -109,7 +109,7 @@ fn test_fmt() {
|
||||
|
||||
#[test]
|
||||
fn cookie_jar() {
|
||||
let cookie_pair = CookiePair::new("foo".to_string(), "bar".to_string());
|
||||
let cookie_pair = CookiePair::new("foo".to_owned(), "bar".to_owned());
|
||||
let cookie_header = Cookie(vec![cookie_pair]);
|
||||
let jar = cookie_header.to_cookie_jar(&[]);
|
||||
let new_cookie_header = Cookie::from_cookie_jar(&jar);
|
||||
|
||||
@@ -28,29 +28,29 @@ header! {
|
||||
// From the RFC
|
||||
test_header!(test1,
|
||||
vec![b"\"xyzzy\""],
|
||||
Some(ETag(EntityTag::new(false, "xyzzy".to_string()))));
|
||||
Some(ETag(EntityTag::new(false, "xyzzy".to_owned()))));
|
||||
test_header!(test2,
|
||||
vec![b"W/\"xyzzy\""],
|
||||
Some(ETag(EntityTag::new(true, "xyzzy".to_string()))));
|
||||
Some(ETag(EntityTag::new(true, "xyzzy".to_owned()))));
|
||||
test_header!(test3,
|
||||
vec![b"\"\""],
|
||||
Some(ETag(EntityTag::new(false, "".to_string()))));
|
||||
Some(ETag(EntityTag::new(false, "".to_owned()))));
|
||||
// Own tests
|
||||
test_header!(test4,
|
||||
vec![b"\"foobar\""],
|
||||
Some(ETag(EntityTag::new(false, "foobar".to_string()))));
|
||||
Some(ETag(EntityTag::new(false, "foobar".to_owned()))));
|
||||
test_header!(test5,
|
||||
vec![b"\"\""],
|
||||
Some(ETag(EntityTag::new(false, "".to_string()))));
|
||||
Some(ETag(EntityTag::new(false, "".to_owned()))));
|
||||
test_header!(test6,
|
||||
vec![b"W/\"weak-etag\""],
|
||||
Some(ETag(EntityTag::new(true, "weak-etag".to_string()))));
|
||||
Some(ETag(EntityTag::new(true, "weak-etag".to_owned()))));
|
||||
test_header!(test7,
|
||||
vec![b"W/\"\x65\x62\""],
|
||||
Some(ETag(EntityTag::new(true, "\u{0065}\u{0062}".to_string()))));
|
||||
Some(ETag(EntityTag::new(true, "\u{0065}\u{0062}".to_owned()))));
|
||||
test_header!(test8,
|
||||
vec![b"W/\"\""],
|
||||
Some(ETag(EntityTag::new(true, "".to_string()))));
|
||||
Some(ETag(EntityTag::new(true, "".to_owned()))));
|
||||
test_header!(test9,
|
||||
vec![b"no-dquotes"],
|
||||
None::<ETag>);
|
||||
|
||||
@@ -83,14 +83,14 @@ mod tests {
|
||||
fn test_host() {
|
||||
let host = Header::parse_header([b"foo.com".to_vec()].as_ref());
|
||||
assert_eq!(host, Some(Host {
|
||||
hostname: "foo.com".to_string(),
|
||||
hostname: "foo.com".to_owned(),
|
||||
port: None
|
||||
}));
|
||||
|
||||
|
||||
let host = Header::parse_header([b"foo.com:8080".to_vec()].as_ref());
|
||||
assert_eq!(host, Some(Host {
|
||||
hostname: "foo.com".to_string(),
|
||||
hostname: "foo.com".to_owned(),
|
||||
port: Some(8080)
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -31,14 +31,14 @@ header! {
|
||||
test1,
|
||||
vec![b"\"xyzzy\""],
|
||||
Some(HeaderField::Items(
|
||||
vec![EntityTag::new(false, "xyzzy".to_string())])));
|
||||
vec![EntityTag::new(false, "xyzzy".to_owned())])));
|
||||
test_header!(
|
||||
test2,
|
||||
vec![b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""],
|
||||
Some(HeaderField::Items(
|
||||
vec![EntityTag::new(false, "xyzzy".to_string()),
|
||||
EntityTag::new(false, "r2d2xxxx".to_string()),
|
||||
EntityTag::new(false, "c3piozzzz".to_string())])));
|
||||
vec![EntityTag::new(false, "xyzzy".to_owned()),
|
||||
EntityTag::new(false, "r2d2xxxx".to_owned()),
|
||||
EntityTag::new(false, "c3piozzzz".to_owned())])));
|
||||
test_header!(test3, vec![b"*"], Some(IfMatch::Any));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,8 +52,8 @@ mod tests {
|
||||
|
||||
if_none_match = Header::parse_header([b"\"foobar\", W/\"weak-etag\"".to_vec()].as_ref());
|
||||
let mut entities: Vec<EntityTag> = Vec::new();
|
||||
let foobar_etag = EntityTag::new(false, "foobar".to_string());
|
||||
let weak_etag = EntityTag::new(true, "weak-etag".to_string());
|
||||
let foobar_etag = EntityTag::new(false, "foobar".to_owned());
|
||||
let weak_etag = EntityTag::new(true, "weak-etag".to_owned());
|
||||
entities.push(foobar_etag);
|
||||
entities.push(weak_etag);
|
||||
assert_eq!(if_none_match, Some(IfNoneMatch::Items(entities)));
|
||||
|
||||
@@ -128,12 +128,12 @@ macro_rules! test_header {
|
||||
let result_cmp: Vec<String> = result
|
||||
.to_ascii_lowercase()
|
||||
.split(' ')
|
||||
.map(|x| x.to_string())
|
||||
.map(|x| x.to_owned())
|
||||
.collect();
|
||||
let expected_cmp: Vec<String> = expected
|
||||
.to_ascii_lowercase()
|
||||
.split(' ')
|
||||
.map(|x| x.to_string())
|
||||
.map(|x| x.to_owned())
|
||||
.collect();
|
||||
assert_eq!(result_cmp.concat(), expected_cmp.concat());
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ fn test_parse_header() {
|
||||
let b = Pragma::NoCache;
|
||||
assert_eq!(a, b);
|
||||
let c: Pragma = Header::parse_header([b"FoObar".to_vec()].as_ref()).unwrap();
|
||||
let d = Pragma::Ext("FoObar".to_string());
|
||||
let d = Pragma::Ext("FoObar".to_owned());
|
||||
assert_eq!(c, d);
|
||||
let e: Option<Pragma> = Header::parse_header([b"".to_vec()].as_ref());
|
||||
assert_eq!(e, None);
|
||||
|
||||
@@ -117,7 +117,7 @@ impl SetCookie {
|
||||
#[test]
|
||||
fn test_parse() {
|
||||
let h = Header::parse_header(&[b"foo=bar; HttpOnly".to_vec()][..]);
|
||||
let mut c1 = Cookie::new("foo".to_string(), "bar".to_string());
|
||||
let mut c1 = Cookie::new("foo".to_owned(), "bar".to_owned());
|
||||
c1.httponly = true;
|
||||
|
||||
assert_eq!(h, Some(SetCookie(vec![c1])));
|
||||
@@ -127,10 +127,10 @@ fn test_parse() {
|
||||
fn test_fmt() {
|
||||
use header::Headers;
|
||||
|
||||
let mut cookie = Cookie::new("foo".to_string(), "bar".to_string());
|
||||
let mut cookie = Cookie::new("foo".to_owned(), "bar".to_owned());
|
||||
cookie.httponly = true;
|
||||
cookie.path = Some("/p".to_string());
|
||||
let cookies = SetCookie(vec![cookie, Cookie::new("baz".to_string(), "quux".to_string())]);
|
||||
cookie.path = Some("/p".to_owned());
|
||||
let cookies = SetCookie(vec![cookie, Cookie::new("baz".to_owned(), "quux".to_owned())]);
|
||||
let mut headers = Headers::new();
|
||||
headers.set(cookies);
|
||||
|
||||
@@ -142,7 +142,7 @@ fn test_fmt() {
|
||||
#[test]
|
||||
fn cookie_jar() {
|
||||
let jar = CookieJar::new(b"secret");
|
||||
let cookie = Cookie::new("foo".to_string(), "bar".to_string());
|
||||
let cookie = Cookie::new("foo".to_owned(), "bar".to_owned());
|
||||
jar.encrypted().add(cookie);
|
||||
|
||||
let cookies = SetCookie::from_cookie_jar(&jar);
|
||||
|
||||
@@ -34,10 +34,10 @@ header! {
|
||||
test1,
|
||||
vec![b"HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11"],
|
||||
Some(Upgrade(vec![
|
||||
Protocol::new(ProtocolName::Http, Some("2.0".to_string())),
|
||||
Protocol::new(ProtocolName::Unregistered("SHTTP".to_string()), Some("1.3".to_string())),
|
||||
Protocol::new(ProtocolName::Unregistered("IRC".to_string()), Some("6.9".to_string())),
|
||||
Protocol::new(ProtocolName::Unregistered("RTA".to_string()), Some("x11".to_string())),
|
||||
Protocol::new(ProtocolName::Http, Some("2.0".to_owned())),
|
||||
Protocol::new(ProtocolName::Unregistered("SHTTP".to_owned()), Some("1.3".to_owned())),
|
||||
Protocol::new(ProtocolName::Unregistered("IRC".to_owned()), Some("6.9".to_owned())),
|
||||
Protocol::new(ProtocolName::Unregistered("RTA".to_owned()), Some("x11".to_owned())),
|
||||
])));
|
||||
// Own tests
|
||||
test_header!(
|
||||
@@ -79,7 +79,7 @@ impl FromStr for ProtocolName {
|
||||
if UniCase(s) == UniCase("websocket") {
|
||||
ProtocolName::WebSocket
|
||||
} else {
|
||||
ProtocolName::Unregistered(s.to_string())
|
||||
ProtocolName::Unregistered(s.to_owned())
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -118,7 +118,7 @@ impl FromStr for Protocol {
|
||||
type Err =();
|
||||
fn from_str(s: &str) -> Result<Protocol, ()> {
|
||||
let mut parts = s.splitn(2, '/');
|
||||
Ok(Protocol::new(try!(parts.next().unwrap().parse()), parts.next().map(|x| x.to_string())))
|
||||
Ok(Protocol::new(try!(parts.next().unwrap().parse()), parts.next().map(|x| x.to_owned())))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,6 @@ header! {
|
||||
// Testcase from RFC
|
||||
test_header!(test1, vec![b"CERN-LineMode/2.15 libwww/2.17b3"]);
|
||||
// Own testcase
|
||||
test_header!(test2, vec![b"Bunnies"], Some(UserAgent("Bunnies".to_string())));
|
||||
test_header!(test2, vec![b"Bunnies"], Some(UserAgent("Bunnies".to_owned())));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user