Skip to content

Commit

Permalink
Merge pull request #99 from frewsxcv/cleanup
Browse files Browse the repository at this point in the history
General cleanup and modernization
  • Loading branch information
SimonSapin committed Apr 27, 2015
2 parents 37970e0 + 42da7aa commit 6625313
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/format.rs
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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());
Expand All @@ -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
Expand All @@ -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());
}
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
}
}
Expand All @@ -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.
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
13 changes: 5 additions & 8 deletions src/percent_encoding.rs
Expand Up @@ -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])
}
}
Expand Down Expand Up @@ -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
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/punycode.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions src/tests.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 6625313

Please sign in to comment.