Просмотр исходного кода

Merge pull request #99 from frewsxcv/cleanup

General cleanup and modernization
Simon Sapin 11 лет назад
Родитель
Сommit
662531313a
5 измененных файлов с 18 добавлено и 21 удалено
  1. 4 4
      src/format.rs
  2. 5 5
      src/lib.rs
  3. 5 8
      src/percent_encoding.rs
  4. 2 2
      src/punycode.rs
  5. 2 2
      src/tests.rs

+ 4 - 4
src/format.rs

@@ -26,7 +26,7 @@ impl<'a, T: fmt::Display> fmt::Display for PathFormatter<'a, T> {
         if self.path.is_empty() {
             formatter.write_str("/")
         } else {
-            for path_part in self.path.iter() {
+            for path_part in self.path {
                 try!("/".fmt(formatter));
                 try!(path_part.fmt(formatter));
             }
@@ -95,7 +95,7 @@ mod tests {
             (vec!["test", "path"], "/test/path"),
             (vec!["test", "path", ""], "/test/path/")
         ];
-        for &(ref path, result) in data.iter() {
+        for &(ref path, result) in &data {
             assert_eq!(PathFormatter {
                 path: path
             }.to_string(), result.to_string());
@@ -113,7 +113,7 @@ mod tests {
             ("username", Some(""), "username:@"),
             ("username", Some("password"), "username:password@")
         ];
-        for &(username, password, result) in data.iter() {
+        for &(username, password, result) in &data {
             assert_eq!(UserInfoFormatter {
                 username: username,
                 password: password
@@ -133,7 +133,7 @@ mod tests {
             ("http://slashquery.com/path/?q=something", "http://slashquery.com/path/?q=something"),
             ("http://noslashquery.com/path?q=something", "http://noslashquery.com/path?q=something")
         ];
-        for &(input, result) in data.iter() {
+        for &(input, result) in &data {
             let url = Url::parse(input).unwrap();
             assert_eq!(url.to_string(), result.to_string());
         }

+ 5 - 5
src/lib.rs

@@ -616,7 +616,7 @@ impl Url {
     #[inline]
     pub fn password<'a>(&'a self) -> Option<&'a str> {
         self.relative_scheme_data().and_then(|scheme_data|
-            scheme_data.password.as_ref().map(|password| &**password))
+            scheme_data.password.as_ref().map(|password| password as &str))
     }
 
     /// If the URL is in a *relative scheme*, return a mutable reference to its password, if any.
@@ -878,7 +878,7 @@ impl RelativeSchemeData {
     pub fn serialize_userinfo(&self) -> String {
         UserInfoFormatter {
             username: &self.username,
-            password: self.password.as_ref().map(|s| &**s)
+            password: self.password.as_ref().map(|s| s as &str)
         }.to_string()
     }
 }
@@ -892,7 +892,7 @@ impl fmt::Display for RelativeSchemeData {
         // Write the user info.
         try!(UserInfoFormatter {
             username: &self.username,
-            password: self.password.as_ref().map(|s| &**s)
+            password: self.password.as_ref().map(|s| s as &str)
         }.fmt(formatter));
 
         // Write the host.
@@ -970,7 +970,7 @@ fn file_url_path_to_pathbuf(path: &[String]) -> Result<PathBuf, ()> {
         return Ok(PathBuf::from("/"))
     }
     let mut bytes = Vec::new();
-    for path_part in path.iter() {
+    for path_part in path {
         bytes.push(b'/');
         percent_decode_to(path_part.as_bytes(), &mut bytes);
     }
@@ -994,7 +994,7 @@ fn file_url_path_to_pathbuf(path: &[String]) -> Result<PathBuf, ()> {
         return Err(())
     }
     let mut string = prefix.to_string();
-    for path_part in path[1..].iter() {
+    for path_part in path[1..] {
         string.push('\\');
 
         // Currently non-unicode windows paths cannot be represented

+ 5 - 8
src/percent_encoding.rs

@@ -61,7 +61,7 @@ pub static FORM_URLENCODED_ENCODE_SET: EncodeSet = EncodeSet {
 /// The pushed strings are within the ASCII range.
 #[inline]
 pub fn percent_encode_to(input: &[u8], encode_set: EncodeSet, output: &mut String) {
-    for &byte in input.iter() {
+    for &byte in input {
         output.push_str(encode_set.map[byte as usize])
     }
 }
@@ -104,13 +104,10 @@ pub fn percent_decode_to(input: &[u8], output: &mut Vec<u8>) {
     while i < input.len() {
         let c = input[i];
         if c == b'%' && i + 2 < input.len() {
-            match (from_hex(input[i + 1]), from_hex(input[i + 2])) {
-                (Some(h), Some(l)) => {
-                    output.push(h * 0x10 + l);
-                    i += 3;
-                    continue
-                },
-                _ => (),
+            if let (Some(h), Some(l)) = (from_hex(input[i + 1]), from_hex(input[i + 2])) {
+                output.push(h * 0x10 + l);
+                i += 3;
+                continue
             }
         }
 

+ 2 - 2
src/punycode.rs

@@ -165,7 +165,7 @@ pub fn encode(input: &[char]) -> Option<String> {
         // Increase delta to advance the decoder’s <code_point,i> state to <min_code_point,0>
         delta += (min_code_point - code_point) * (processed + 1);
         code_point = min_code_point;
-        for &c in input.iter() {
+        for &c in input {
             let c = c as u32;
             if c < code_point {
                 delta += 1;
@@ -251,7 +251,7 @@ mod tests {
     fn test_punycode() {
 
         match Json::from_str(include_str!("punycode_tests.json")) {
-            Ok(Json::Array(tests)) => for test in tests.iter() {
+            Ok(Json::Array(tests)) => for test in &tests {
                 match test {
                     &Json::Object(ref o) => one_test(
                         get_string(o, "description"),

+ 2 - 2
src/tests.rs

@@ -13,7 +13,7 @@ use super::{UrlParser, Url, SchemeData, RelativeSchemeData, Host};
 
 #[test]
 fn url_parsing() {
-    for test in parse_test_data(include_str!("urltestdata.txt")).into_iter() {
+    for test in parse_test_data(include_str!("urltestdata.txt")) {
         let Test {
             input,
             base,
@@ -138,7 +138,7 @@ fn parse_test_data(input: &str) -> Vec<Test> {
             fragment: None,
             expected_failure: expected_failure,
         };
-        for piece in pieces.into_iter() {
+        for piece in pieces {
             if piece == "" || piece.starts_with("#") {
                 continue
             }