Эх сурвалжийг харах

Remove usage of .as_slice()

Simon Sapin 11 жил өмнө
parent
commit
16923fb0a9

+ 2 - 2
src/encoding.rs

@@ -42,7 +42,7 @@ impl EncodingOverride {
     }
     }
 
 
     pub fn lookup(label: &[u8]) -> Option<EncodingOverride> {
     pub fn lookup(label: &[u8]) -> Option<EncodingOverride> {
-        ::std::str::from_utf8(label.as_slice())
+        ::std::str::from_utf8(label)
         .ok()
         .ok()
         .and_then(encoding_from_whatwg_label)
         .and_then(encoding_from_whatwg_label)
         .map(EncodingOverride::from_encoding)
         .map(EncodingOverride::from_encoding)
@@ -62,7 +62,7 @@ impl EncodingOverride {
     pub fn encode<'a>(&self, input: &'a str) -> Cow<'a, Vec<u8>, [u8]> {
     pub fn encode<'a>(&self, input: &'a str) -> Cow<'a, Vec<u8>, [u8]> {
         match self.encoding {
         match self.encoding {
             Some(encoding) => Cow::Owned(
             Some(encoding) => Cow::Owned(
-                encoding.encode(input.as_slice(), EncoderTrap::NcrEscape).unwrap()),
+                encoding.encode(input, EncoderTrap::NcrEscape).unwrap()),
             None => Cow::Borrowed(input.as_bytes()),  // UTF-8
             None => Cow::Borrowed(input.as_bytes()),  // UTF-8
         }
         }
     }
     }

+ 10 - 10
src/form_urlencoded.rs

@@ -56,7 +56,7 @@ fn parse_internal(input: &[u8], mut encoding_override: EncodingOverride, mut use
         if !piece.is_empty() {
         if !piece.is_empty() {
             let (name, value) = match piece.position_elem(&b'=') {
             let (name, value) = match piece.position_elem(&b'=') {
                 Some(position) => (&piece[..position], &piece[position + 1..]),
                 Some(position) => (&piece[..position], &piece[position + 1..]),
-                None => (piece, [].as_slice())
+                None => (piece, &[][])
             };
             };
 
 
             #[inline]
             #[inline]
@@ -66,8 +66,8 @@ fn parse_internal(input: &[u8], mut encoding_override: EncodingOverride, mut use
 
 
             let name = replace_plus(name);
             let name = replace_plus(name);
             let value = replace_plus(value);
             let value = replace_plus(value);
-            if use_charset && name.as_slice() == b"_charset_" {
-                if let Some(encoding) = EncodingOverride::lookup(value.as_slice()) {
+            if use_charset && name == b"_charset_" {
+                if let Some(encoding) = EncodingOverride::lookup(&value) {
                     encoding_override = encoding;
                     encoding_override = encoding;
                 }
                 }
                 use_charset = false;
                 use_charset = false;
@@ -80,8 +80,8 @@ fn parse_internal(input: &[u8], mut encoding_override: EncodingOverride, mut use
     }
     }
 
 
     Some(pairs.into_iter().map(|(name, value)| (
     Some(pairs.into_iter().map(|(name, value)| (
-        encoding_override.decode(percent_decode(name.as_slice()).as_slice()),
-        encoding_override.decode(percent_decode(value.as_slice()).as_slice())
+        encoding_override.decode(&percent_decode(&name)),
+        encoding_override.decode(&percent_decode(&value))
     )).collect())
     )).collect())
 }
 }
 
 
@@ -90,7 +90,7 @@ fn parse_internal(input: &[u8], mut encoding_override: EncodingOverride, mut use
 /// into a string in the `application/x-www-form-urlencoded` format.
 /// into a string in the `application/x-www-form-urlencoded` format.
 #[inline]
 #[inline]
 pub fn serialize_owned(pairs: &[(String, String)]) -> String {
 pub fn serialize_owned(pairs: &[(String, String)]) -> String {
-    serialize(pairs.iter().map(|&(ref n, ref v)| (n.as_slice(), v.as_slice())))
+    serialize(pairs.iter().map(|&(ref n, ref v)| (&**n, &**v)))
 }
 }
 
 
 
 
@@ -147,12 +147,12 @@ fn serialize_internal<'a, I>(pairs: I, encoding_override: EncodingOverride) -> S
 
 
 #[test]
 #[test]
 fn test_form_urlencoded() {
 fn test_form_urlencoded() {
-    let pairs = [
+    let pairs = &[
         ("foo".to_string(), "é&".to_string()),
         ("foo".to_string(), "é&".to_string()),
         ("bar".to_string(), "".to_string()),
         ("bar".to_string(), "".to_string()),
         ("foo".to_string(), "#".to_string())
         ("foo".to_string(), "#".to_string())
     ];
     ];
-    let encoded = serialize_owned(pairs.as_slice());
-    assert_eq!(encoded.as_slice(), "foo=%C3%A9%26&bar=&foo=%23");
-    assert_eq!(parse(encoded.as_bytes()), pairs.as_slice().to_vec());
+    let encoded = serialize_owned(pairs);
+    assert_eq!(encoded, "foo=%C3%A9%26&bar=&foo=%23");
+    assert_eq!(parse(encoded.as_bytes()), pairs.to_vec());
 }
 }

+ 4 - 4
src/format.rs

@@ -43,7 +43,7 @@ pub struct UserInfoFormatter<'a> {
 
 
     /// URL password as an optional string slice.
     /// URL password as an optional string slice.
     ///
     ///
-    /// You can convert an `Option<String>` with `.as_ref().map(|s| s.as_slice())`.
+    /// You can convert an `Option<String>` with `.as_ref().map(|s| s)`.
     pub password: Option<&'a str>
     pub password: Option<&'a str>
 }
 }
 
 
@@ -69,12 +69,12 @@ pub struct UrlNoFragmentFormatter<'a> {
 
 
 impl<'a> fmt::Display for UrlNoFragmentFormatter<'a> {
 impl<'a> fmt::Display for UrlNoFragmentFormatter<'a> {
     fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
     fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
-        try!(formatter.write_str(self.url.scheme.as_slice()));
+        try!(formatter.write_str(&self.url.scheme));
         try!(formatter.write_str(":"));
         try!(formatter.write_str(":"));
         try!(self.url.scheme_data.fmt(formatter));
         try!(self.url.scheme_data.fmt(formatter));
         if let Some(ref query) = self.url.query {
         if let Some(ref query) = self.url.query {
             try!(formatter.write_str("?"));
             try!(formatter.write_str("?"));
-            try!(formatter.write_str(query.as_slice()));
+            try!(formatter.write_str(query));
         }
         }
         Ok(())
         Ok(())
     }
     }
@@ -97,7 +97,7 @@ mod tests {
         ];
         ];
         for &(ref path, result) in data.iter() {
         for &(ref path, result) in data.iter() {
             assert_eq!(PathFormatter {
             assert_eq!(PathFormatter {
-                path: path.as_slice()
+                path: path
             }.to_string(), result.to_string());
             }.to_string(), result.to_string());
         }
         }
     }
     }

+ 4 - 4
src/host.rs

@@ -54,13 +54,13 @@ impl Host {
             }
             }
         } else {
         } else {
             let decoded = percent_decode(input.as_bytes());
             let decoded = percent_decode(input.as_bytes());
-            let domain = String::from_utf8_lossy(decoded.as_slice());
+            let domain = String::from_utf8_lossy(&decoded);
             // TODO: Remove this check and use IDNA "domain to ASCII"
             // TODO: Remove this check and use IDNA "domain to ASCII"
-            if !domain.as_slice().is_ascii() {
+            if !domain.is_ascii() {
                 Err(ParseError::NonAsciiDomainsNotSupportedYet)
                 Err(ParseError::NonAsciiDomainsNotSupportedYet)
-            } else if domain.as_slice().find([
+            } else if domain.find(&[
                 '\0', '\t', '\n', '\r', ' ', '#', '%', '/', ':', '?', '@', '[', '\\', ']'
                 '\0', '\t', '\n', '\r', ' ', '#', '%', '/', ':', '?', '@', '[', '\\', ']'
-            ].as_slice()).is_some() {
+            ][]).is_some() {
                 Err(ParseError::InvalidDomainCharacter)
                 Err(ParseError::InvalidDomainCharacter)
             } else {
             } else {
                 Ok(Host::Domain(domain.to_string().into_ascii_lowercase()))
                 Ok(Host::Domain(domain.to_string().into_ascii_lowercase()))

+ 18 - 18
src/lib.rs

@@ -60,9 +60,9 @@ let issue_list_url = Url::parse(
 assert!(issue_list_url.scheme == "https".to_string());
 assert!(issue_list_url.scheme == "https".to_string());
 assert!(issue_list_url.domain() == Some("github.com"));
 assert!(issue_list_url.domain() == Some("github.com"));
 assert!(issue_list_url.port() == None);
 assert!(issue_list_url.port() == None);
-assert!(issue_list_url.path() == Some(["rust-lang".to_string(),
+assert!(issue_list_url.path() == Some(&["rust-lang".to_string(),
                                         "rust".to_string(),
                                         "rust".to_string(),
-                                        "issues".to_string()].as_slice()));
+                                        "issues".to_string()][]));
 assert!(issue_list_url.query == Some("labels=E-easy&state=open".to_string()));
 assert!(issue_list_url.query == Some("labels=E-easy&state=open".to_string()));
 assert!(issue_list_url.fragment == None);
 assert!(issue_list_url.fragment == None);
 match issue_list_url.scheme_data {
 match issue_list_url.scheme_data {
@@ -561,7 +561,7 @@ impl Url {
     pub fn non_relative_scheme_data<'a>(&'a self) -> Option<&'a str> {
     pub fn non_relative_scheme_data<'a>(&'a self) -> Option<&'a str> {
         match self.scheme_data {
         match self.scheme_data {
             SchemeData::Relative(..) => None,
             SchemeData::Relative(..) => None,
-            SchemeData::NonRelative(ref scheme_data) => Some(scheme_data.as_slice()),
+            SchemeData::NonRelative(ref scheme_data) => Some(scheme_data),
         }
         }
     }
     }
 
 
@@ -596,7 +596,7 @@ impl Url {
     /// If the URL is in a *relative scheme*, return its username.
     /// If the URL is in a *relative scheme*, return its username.
     #[inline]
     #[inline]
     pub fn username<'a>(&'a self) -> Option<&'a str> {
     pub fn username<'a>(&'a self) -> Option<&'a str> {
-        self.relative_scheme_data().map(|scheme_data| scheme_data.username.as_slice())
+        self.relative_scheme_data().map(|scheme_data| &*scheme_data.username)
     }
     }
 
 
     /// If the URL is in a *relative scheme*, return a mutable reference to its username.
     /// If the URL is in a *relative scheme*, return a mutable reference to its username.
@@ -618,7 +618,7 @@ impl Url {
     #[inline]
     #[inline]
     pub fn password<'a>(&'a self) -> Option<&'a str> {
     pub fn password<'a>(&'a self) -> Option<&'a str> {
         self.relative_scheme_data().and_then(|scheme_data|
         self.relative_scheme_data().and_then(|scheme_data|
-            scheme_data.password.as_ref().map(|password| password.as_slice()))
+            scheme_data.password.as_ref().map(|password| &**password))
     }
     }
 
 
     /// If the URL is in a *relative scheme*, return a mutable reference to its password, if any.
     /// If the URL is in a *relative scheme*, return a mutable reference to its password, if any.
@@ -701,7 +701,7 @@ impl Url {
     /// If the URL is in a *relative scheme*, return its path components.
     /// If the URL is in a *relative scheme*, return its path components.
     #[inline]
     #[inline]
     pub fn path<'a>(&'a self) -> Option<&'a [String]> {
     pub fn path<'a>(&'a self) -> Option<&'a [String]> {
-        self.relative_scheme_data().map(|scheme_data| scheme_data.path.as_slice())
+        self.relative_scheme_data().map(|scheme_data| &*scheme_data.path)
     }
     }
 
 
     /// If the URL is in a *relative scheme*, return a mutable reference to its path components.
     /// If the URL is in a *relative scheme*, return a mutable reference to its path components.
@@ -755,15 +755,15 @@ impl Url {
 
 
 impl rustc_serialize::Encodable for Url {
 impl rustc_serialize::Encodable for Url {
     fn encode<S: rustc_serialize::Encoder>(&self, encoder: &mut S) -> Result<(), S::Error> {
     fn encode<S: rustc_serialize::Encoder>(&self, encoder: &mut S) -> Result<(), S::Error> {
-        encoder.emit_str(self.to_string().as_slice())
+        encoder.emit_str(&self.to_string())
     }
     }
 }
 }
 
 
 
 
 impl rustc_serialize::Decodable for Url {
 impl rustc_serialize::Decodable for Url {
     fn decode<D: rustc_serialize::Decoder>(decoder: &mut D) -> Result<Url, D::Error> {
     fn decode<D: rustc_serialize::Decoder>(decoder: &mut D) -> Result<Url, D::Error> {
-        Url::parse(try!(decoder.read_str()).as_slice()).map_err(|error| {
-            decoder.error(format!("URL parsing error: {}", error).as_slice())
+        Url::parse(&*try!(decoder.read_str())).map_err(|error| {
+            decoder.error(&format!("URL parsing error: {}", error))
         })
         })
     }
     }
 }
 }
@@ -774,7 +774,7 @@ impl fmt::Display for Url {
         try!(UrlNoFragmentFormatter{ url: self }.fmt(formatter));
         try!(UrlNoFragmentFormatter{ url: self }.fmt(formatter));
         if let Some(ref fragment) = self.fragment {
         if let Some(ref fragment) = self.fragment {
             try!(formatter.write_str("#"));
             try!(formatter.write_str("#"));
-            try!(formatter.write_str(fragment.as_slice()));
+            try!(formatter.write_str(fragment));
         }
         }
         Ok(())
         Ok(())
     }
     }
@@ -834,7 +834,7 @@ impl RelativeSchemeData {
     pub fn to_file_path<T: FromUrlPath>(&self) -> Result<T, ()> {
     pub fn to_file_path<T: FromUrlPath>(&self) -> Result<T, ()> {
         // FIXME: Figure out what to do w.r.t host.
         // FIXME: Figure out what to do w.r.t host.
         match self.domain() {
         match self.domain() {
-            Some("") | Some("localhost") => FromUrlPath::from_url_path(self.path.as_slice()),
+            Some("") | Some("localhost") => FromUrlPath::from_url_path(&self.path),
             _ => Err(())
             _ => Err(())
         }
         }
     }
     }
@@ -843,7 +843,7 @@ impl RelativeSchemeData {
     #[inline]
     #[inline]
     pub fn domain<'a>(&'a self) -> Option<&'a str> {
     pub fn domain<'a>(&'a self) -> Option<&'a str> {
         match self.host {
         match self.host {
-            Host::Domain(ref domain) => Some(domain.as_slice()),
+            Host::Domain(ref domain) => Some(domain),
             _ => None,
             _ => None,
         }
         }
     }
     }
@@ -870,7 +870,7 @@ impl RelativeSchemeData {
     /// A trailing slash represents an empty last component.
     /// A trailing slash represents an empty last component.
     pub fn serialize_path(&self) -> String {
     pub fn serialize_path(&self) -> String {
         PathFormatter {
         PathFormatter {
-            path: self.path.as_slice()
+            path: &self.path
         }.to_string()
         }.to_string()
     }
     }
 
 
@@ -879,8 +879,8 @@ impl RelativeSchemeData {
     /// Format: "<username>:<password>@".
     /// Format: "<username>:<password>@".
     pub fn serialize_userinfo(&self) -> String {
     pub fn serialize_userinfo(&self) -> String {
         UserInfoFormatter {
         UserInfoFormatter {
-            username: self.username.as_slice(),
-            password: self.password.as_ref().map(|s| s.as_slice())
+            username: &self.username,
+            password: self.password.as_ref().map(|s| &**s)
         }.to_string()
         }.to_string()
     }
     }
 }
 }
@@ -893,8 +893,8 @@ impl fmt::Display for RelativeSchemeData {
 
 
         // Write the user info.
         // Write the user info.
         try!(UserInfoFormatter {
         try!(UserInfoFormatter {
-            username: self.username.as_slice(),
-            password: self.password.as_ref().map(|s| s.as_slice())
+            username: &self.username,
+            password: self.password.as_ref().map(|s| &**s)
         }.fmt(formatter));
         }.fmt(formatter));
 
 
         // Write the host.
         // Write the host.
@@ -910,7 +910,7 @@ impl fmt::Display for RelativeSchemeData {
 
 
         // Write the path.
         // Write the path.
         PathFormatter {
         PathFormatter {
-            path: self.path.as_slice()
+            path: &self.path
         }.fmt(formatter)
         }.fmt(formatter)
     }
     }
 }
 }

+ 10 - 10
src/parser.rs

@@ -93,21 +93,21 @@ pub enum Context {
 
 
 
 
 pub fn parse_url(input: &str, parser: &UrlParser) -> ParseResult<Url> {
 pub fn parse_url(input: &str, parser: &UrlParser) -> ParseResult<Url> {
-    let input = input.trim_matches([' ', '\t', '\n', '\r', '\x0C'].as_slice());
+    let input = input.trim_matches(&[' ', '\t', '\n', '\r', '\x0C'][]);
     let (scheme, remaining) = match parse_scheme(input, Context::UrlParser) {
     let (scheme, remaining) = match parse_scheme(input, Context::UrlParser) {
         Some((scheme, remaining)) => (scheme, remaining),
         Some((scheme, remaining)) => (scheme, remaining),
         // No-scheme state
         // No-scheme state
         None => return match parser.base_url {
         None => return match parser.base_url {
             Some(&Url { ref scheme, scheme_data: SchemeData::Relative(ref base),
             Some(&Url { ref scheme, scheme_data: SchemeData::Relative(ref base),
                         ref query, .. }) => {
                         ref query, .. }) => {
-                let scheme_type = parser.get_scheme_type(scheme.as_slice());
+                let scheme_type = parser.get_scheme_type(&scheme);
                 parse_relative_url(input, scheme.clone(), scheme_type, base, query, parser)
                 parse_relative_url(input, scheme.clone(), scheme_type, base, query, parser)
             },
             },
             Some(_) => Err(ParseError::RelativeUrlWithNonRelativeBase),
             Some(_) => Err(ParseError::RelativeUrlWithNonRelativeBase),
             None => Err(ParseError::RelativeUrlWithoutBase),
             None => Err(ParseError::RelativeUrlWithoutBase),
         },
         },
     };
     };
-    let scheme_type = parser.get_scheme_type(scheme.as_slice());
+    let scheme_type = parser.get_scheme_type(&scheme);
     match scheme_type {
     match scheme_type {
         SchemeType::FileLike => {
         SchemeType::FileLike => {
             // Relative state?
             // Relative state?
@@ -411,7 +411,7 @@ pub fn parse_hostname<'a>(input: &'a str, parser: &UrlParser)
             }
             }
         }
         }
     }
     }
-    let host = try!(Host::parse(host_input.as_slice()));
+    let host = try!(Host::parse(&host_input));
     Ok((host, &input[end..]))
     Ok((host, &input[end..]))
 }
 }
 
 
@@ -463,7 +463,7 @@ fn parse_file_host<'a>(input: &'a str, parser: &UrlParser) -> ParseResult<(Host,
     let host = if host_input.is_empty() {
     let host = if host_input.is_empty() {
         Host::Domain(String::new())
         Host::Domain(String::new())
     } else {
     } else {
-        try!(Host::parse(host_input.as_slice()))
+        try!(Host::parse(&host_input))
     };
     };
     Ok((host, &input[end..]))
     Ok((host, &input[end..]))
 }
 }
@@ -540,7 +540,7 @@ fn parse_path<'a>(base_path: &[String], input: &'a str, context: Context,
                 }
                 }
             }
             }
         }
         }
-        match path_part.as_slice() {
+        match &*path_part {
             ".." | ".%2e" | ".%2E" | "%2e." | "%2E." |
             ".." | ".%2e" | ".%2E" | "%2e." | "%2E." |
             "%2e%2e" | "%2E%2e" | "%2e%2E" | "%2E%2E" => {
             "%2e%2e" | "%2E%2e" | "%2e%2E" | "%2E%2E" => {
                 path.pop();
                 path.pop();
@@ -557,8 +557,8 @@ fn parse_path<'a>(base_path: &[String], input: &'a str, context: Context,
                 if scheme_type == SchemeType::FileLike
                 if scheme_type == SchemeType::FileLike
                    && path.is_empty()
                    && path.is_empty()
                    && path_part.len() == 2
                    && path_part.len() == 2
-                   && starts_with_ascii_alpha(path_part.as_slice())
-                   && path_part.as_slice().char_at(1) == '|' {
+                   && starts_with_ascii_alpha(&path_part)
+                   && path_part.char_at(1) == '|' {
                     // Windows drive letter quirk
                     // Windows drive letter quirk
                     unsafe {
                     unsafe {
                         path_part.as_mut_vec()[1] = b':'
                         path_part.as_mut_vec()[1] = b':'
@@ -637,8 +637,8 @@ pub fn parse_query<'a>(input: &'a str, context: Context, parser: &UrlParser)
         }
         }
     }
     }
 
 
-    let query_bytes = parser.query_encoding_override.encode(query.as_slice());
-    Ok((percent_encode(query_bytes.as_slice(), QUERY_ENCODE_SET), remaining))
+    let query_bytes = parser.query_encoding_override.encode(&query);
+    Ok((percent_encode(&query_bytes, QUERY_ENCODE_SET), remaining))
 }
 }
 
 
 
 

+ 1 - 1
src/percent_encoding.rs

@@ -135,7 +135,7 @@ pub fn percent_decode(input: &[u8]) -> Vec<u8> {
 /// will be replaced � U+FFFD, the replacement character.
 /// will be replaced � U+FFFD, the replacement character.
 #[inline]
 #[inline]
 pub fn lossy_utf8_percent_decode(input: &[u8]) -> String {
 pub fn lossy_utf8_percent_decode(input: &[u8]) -> String {
-    String::from_utf8_lossy(percent_decode(input).as_slice()).to_string()
+    String::from_utf8_lossy(&percent_decode(input)).to_string()
 }
 }
 
 
 #[inline]
 #[inline]

+ 6 - 6
src/punycode.rs

@@ -131,7 +131,7 @@ pub fn decode(input: &str) -> Option<Vec<char>> {
 /// This is a convenience wrapper around `encode`.
 /// This is a convenience wrapper around `encode`.
 #[inline]
 #[inline]
 pub fn encode_str(input: &str) -> Option<String> {
 pub fn encode_str(input: &str) -> Option<String> {
-    encode(input.chars().collect::<Vec<char>>().as_slice())
+    encode(&input.chars().collect::<Vec<char>>())
 }
 }
 
 
 
 
@@ -223,25 +223,25 @@ mod tests {
             None => panic!("Decoding {} failed.", encoded),
             None => panic!("Decoding {} failed.", encoded),
             Some(result) => {
             Some(result) => {
                 let result = result.into_iter().collect::<String>();
                 let result = result.into_iter().collect::<String>();
-                assert!(result.as_slice() == decoded,
+                assert!(result == decoded,
                         format!("Incorrect decoding of {}:\n   {}\n!= {}\n{}",
                         format!("Incorrect decoding of {}:\n   {}\n!= {}\n{}",
-                                encoded, result.as_slice(), decoded, description))
+                                encoded, result, decoded, description))
             }
             }
         }
         }
 
 
         match encode_str(decoded) {
         match encode_str(decoded) {
             None => panic!("Encoding {} failed.", decoded),
             None => panic!("Encoding {} failed.", decoded),
             Some(result) => {
             Some(result) => {
-                assert!(result.as_slice() == encoded,
+                assert!(result == encoded,
                         format!("Incorrect encoding of {}:\n   {}\n!= {}\n{}",
                         format!("Incorrect encoding of {}:\n   {}\n!= {}\n{}",
-                                decoded, result.as_slice(), encoded, description))
+                                decoded, result, encoded, description))
             }
             }
         }
         }
     }
     }
 
 
     fn get_string<'a>(map: &'a Object, key: &str) -> &'a str {
     fn get_string<'a>(map: &'a Object, key: &str) -> &'a str {
         match map.get(&key.to_string()) {
         match map.get(&key.to_string()) {
-            Some(&Json::String(ref s)) => s.as_slice(),
+            Some(&Json::String(ref s)) => s,
             None => "",
             None => "",
             _ => panic!(),
             _ => panic!(),
         }
         }

+ 8 - 8
src/tests.rs

@@ -29,11 +29,11 @@ fn url_parsing() {
             fragment: expected_fragment,
             fragment: expected_fragment,
             expected_failure,
             expected_failure,
         } = test;
         } = test;
-        let base = match Url::parse(base.as_slice()) {
+        let base = match Url::parse(&base) {
             Ok(base) => base,
             Ok(base) => base,
             Err(message) => panic!("Error parsing base {}: {}", base, message)
             Err(message) => panic!("Error parsing base {}: {}", base, message)
         };
         };
-        let url = UrlParser::new().base_url(&base).parse(input.as_slice());
+        let url = UrlParser::new().base_url(&base).parse(&input);
         if expected_scheme.is_none() {
         if expected_scheme.is_none() {
             if url.is_ok() && !expected_failure {
             if url.is_ok() && !expected_failure {
                 panic!("Expected a parse error for URL {}", input);
                 panic!("Expected a parse error for URL {}", input);
@@ -184,7 +184,7 @@ fn unescape(input: &str) -> String {
                             hex.push(chars.next().unwrap());
                             hex.push(chars.next().unwrap());
                             hex.push(chars.next().unwrap());
                             hex.push(chars.next().unwrap());
                             hex.push(chars.next().unwrap());
                             hex.push(chars.next().unwrap());
-                            from_str_radix(hex.as_slice(), 16).ok()
+                            from_str_radix(&hex, 16).ok()
                                 .and_then(char::from_u32).unwrap()
                                 .and_then(char::from_u32).unwrap()
                         }
                         }
                         _ => panic!("Invalid test data input"),
                         _ => panic!("Invalid test data input"),
@@ -209,7 +209,7 @@ fn file_paths() {
 
 
     let mut url = Url::from_file_path(&path::posix::Path::new("/foo/bar")).unwrap();
     let mut url = Url::from_file_path(&path::posix::Path::new("/foo/bar")).unwrap();
     assert_eq!(url.host(), Some(&Host::Domain("".to_string())));
     assert_eq!(url.host(), Some(&Host::Domain("".to_string())));
-    assert_eq!(url.path(), Some(["foo".to_string(), "bar".to_string()].as_slice()));
+    assert_eq!(url.path(), Some(&["foo".to_string(), "bar".to_string()][]));
     assert!(url.to_file_path() == Ok(path::posix::Path::new("/foo/bar")));
     assert!(url.to_file_path() == Ok(path::posix::Path::new("/foo/bar")));
 
 
     url.path_mut().unwrap()[1] = "ba\0r".to_string();
     url.path_mut().unwrap()[1] = "ba\0r".to_string();
@@ -225,7 +225,7 @@ fn file_paths() {
 
 
     let mut url = Url::from_file_path(&path::windows::Path::new(r"C:\foo\bar")).unwrap();
     let mut url = Url::from_file_path(&path::windows::Path::new(r"C:\foo\bar")).unwrap();
     assert_eq!(url.host(), Some(&Host::Domain("".to_string())));
     assert_eq!(url.host(), Some(&Host::Domain("".to_string())));
-    assert_eq!(url.path(), Some(["C:".to_string(), "foo".to_string(), "bar".to_string()].as_slice()));
+    assert_eq!(url.path(), Some(&["C:".to_string(), "foo".to_string(), "bar".to_string()][]));
     assert!(url.to_file_path::<path::windows::Path>()
     assert!(url.to_file_path::<path::windows::Path>()
             == Ok(path::windows::Path::new(r"C:\foo\bar")));
             == Ok(path::windows::Path::new(r"C:\foo\bar")));
 
 
@@ -252,10 +252,10 @@ fn directory_paths() {
 
 
     let url = Url::from_directory_path(&path::posix::Path::new("/foo/bar")).unwrap();
     let url = Url::from_directory_path(&path::posix::Path::new("/foo/bar")).unwrap();
     assert_eq!(url.host(), Some(&Host::Domain("".to_string())));
     assert_eq!(url.host(), Some(&Host::Domain("".to_string())));
-    assert_eq!(url.path(), Some(["foo".to_string(), "bar".to_string(), "".to_string()].as_slice()));
+    assert_eq!(url.path(), Some(&["foo".to_string(), "bar".to_string(), "".to_string()][]));
 
 
     let url = Url::from_directory_path(&path::windows::Path::new(r"C:\foo\bar")).unwrap();
     let url = Url::from_directory_path(&path::windows::Path::new(r"C:\foo\bar")).unwrap();
     assert_eq!(url.host(), Some(&Host::Domain("".to_string())));
     assert_eq!(url.host(), Some(&Host::Domain("".to_string())));
-    assert_eq!(url.path(), Some([
-        "C:".to_string(), "foo".to_string(), "bar".to_string(), "".to_string()].as_slice()));
+    assert_eq!(url.path(), Some(&[
+        "C:".to_string(), "foo".to_string(), "bar".to_string(), "".to_string()][]));
 }
 }

+ 5 - 5
src/urlutils.rs

@@ -38,7 +38,7 @@ trait UrlUtils {
 impl<'a> UrlUtils for UrlUtilsWrapper<'a> {
 impl<'a> UrlUtils for UrlUtilsWrapper<'a> {
     /// `URLUtils.protocol` setter
     /// `URLUtils.protocol` setter
     fn set_scheme(&mut self, input: &str) -> ParseResult<()> {
     fn set_scheme(&mut self, input: &str) -> ParseResult<()> {
-        match ::parser::parse_scheme(input.as_slice(), Context::Setter) {
+        match ::parser::parse_scheme(input, Context::Setter) {
             Some((scheme, _)) => {
             Some((scheme, _)) => {
                 self.url.scheme = scheme;
                 self.url.scheme = scheme;
                 Ok(())
                 Ok(())
@@ -78,7 +78,7 @@ impl<'a> UrlUtils for UrlUtilsWrapper<'a> {
             SchemeData::Relative(RelativeSchemeData {
             SchemeData::Relative(RelativeSchemeData {
                 ref mut host, ref mut port, ref mut default_port, ..
                 ref mut host, ref mut port, ref mut default_port, ..
             }) => {
             }) => {
-                let scheme_type = self.parser.get_scheme_type(self.url.scheme.as_slice());
+                let scheme_type = self.parser.get_scheme_type(&self.url.scheme);
                 let (new_host, new_port, new_default_port, _) = try!(::parser::parse_host(
                 let (new_host, new_port, new_default_port, _) = try!(::parser::parse_host(
                     input, scheme_type, self.parser));
                     input, scheme_type, self.parser));
                 *host = new_host;
                 *host = new_host;
@@ -106,7 +106,7 @@ impl<'a> UrlUtils for UrlUtilsWrapper<'a> {
     fn set_port(&mut self, input: &str) -> ParseResult<()> {
     fn set_port(&mut self, input: &str) -> ParseResult<()> {
         match self.url.scheme_data {
         match self.url.scheme_data {
             SchemeData::Relative(RelativeSchemeData { ref mut port, ref mut default_port, .. }) => {
             SchemeData::Relative(RelativeSchemeData { ref mut port, ref mut default_port, .. }) => {
-                let scheme_type = self.parser.get_scheme_type(self.url.scheme.as_slice());
+                let scheme_type = self.parser.get_scheme_type(&self.url.scheme);
                 if scheme_type == SchemeType::FileLike {
                 if scheme_type == SchemeType::FileLike {
                     return Err(ParseError::CannotSetPortWithFileLikeScheme);
                     return Err(ParseError::CannotSetPortWithFileLikeScheme);
                 }
                 }
@@ -124,7 +124,7 @@ impl<'a> UrlUtils for UrlUtilsWrapper<'a> {
     fn set_path(&mut self, input: &str) -> ParseResult<()> {
     fn set_path(&mut self, input: &str) -> ParseResult<()> {
         match self.url.scheme_data {
         match self.url.scheme_data {
             SchemeData::Relative(RelativeSchemeData { ref mut path, .. }) => {
             SchemeData::Relative(RelativeSchemeData { ref mut path, .. }) => {
-                let scheme_type = self.parser.get_scheme_type(self.url.scheme.as_slice());
+                let scheme_type = self.parser.get_scheme_type(&self.url.scheme);
                 let (new_path, _) = try!(::parser::parse_path_start(
                 let (new_path, _) = try!(::parser::parse_path_start(
                     input, Context::Setter, scheme_type, self.parser));
                     input, Context::Setter, scheme_type, self.parser));
                 *path = new_path;
                 *path = new_path;
@@ -149,7 +149,7 @@ impl<'a> UrlUtils for UrlUtilsWrapper<'a> {
 
 
     /// `URLUtils.hash` setter
     /// `URLUtils.hash` setter
     fn set_fragment(&mut self, input: &str) -> ParseResult<()> {
     fn set_fragment(&mut self, input: &str) -> ParseResult<()> {
-        if self.url.scheme.as_slice() == "javascript" {
+        if self.url.scheme == "javascript" {
             return Err(ParseError::CannotSetJavascriptFragment)
             return Err(ParseError::CannotSetJavascriptFragment)
         }
         }
         self.url.fragment = if input.is_empty() {
         self.url.fragment = if input.is_empty() {