|
@@ -119,16 +119,17 @@ assert!(css_url.serialize() == "http://servo.github.io/rust-url/main.css".to_str
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
-#![feature(core, std_misc)]
|
|
|
|
|
|
|
+#![feature(std_misc, convert)]
|
|
|
|
|
+#![cfg_attr(test, feature(core))]
|
|
|
|
|
|
|
|
-extern crate "rustc-serialize" as rustc_serialize;
|
|
|
|
|
|
|
+extern crate rustc_serialize;
|
|
|
|
|
|
|
|
#[macro_use]
|
|
#[macro_use]
|
|
|
extern crate matches;
|
|
extern crate matches;
|
|
|
|
|
|
|
|
use std::fmt::{self, Formatter};
|
|
use std::fmt::{self, Formatter};
|
|
|
use std::hash;
|
|
use std::hash;
|
|
|
-use std::path::{Path, PathBuf, AsPath};
|
|
|
|
|
|
|
+use std::path::{Path, PathBuf};
|
|
|
|
|
|
|
|
pub use host::{Host, Ipv6Address};
|
|
pub use host::{Host, Ipv6Address};
|
|
|
pub use parser::{ErrorHandler, ParseResult, ParseError};
|
|
pub use parser::{ErrorHandler, ParseResult, ParseError};
|
|
@@ -479,8 +480,8 @@ impl Url {
|
|
|
///
|
|
///
|
|
|
/// This returns `Err` if the given path is not absolute
|
|
/// This returns `Err` if the given path is not absolute
|
|
|
/// or, with a Windows path, if the prefix is not a disk prefix (e.g. `C:`).
|
|
/// or, with a Windows path, if the prefix is not a disk prefix (e.g. `C:`).
|
|
|
- pub fn from_file_path<P: AsPath>(path: P) -> Result<Url, ()> {
|
|
|
|
|
- let path = try!(path_to_file_url_path(path.as_path()));
|
|
|
|
|
|
|
+ pub fn from_file_path<P: AsRef<Path>>(path: P) -> Result<Url, ()> {
|
|
|
|
|
+ let path = try!(path_to_file_url_path(path.as_ref()));
|
|
|
Ok(Url::from_path_common(path))
|
|
Ok(Url::from_path_common(path))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -501,8 +502,8 @@ impl Url {
|
|
|
/// as the base URL is `file:///var/index.html`, which might not be what was intended.
|
|
/// as the base URL is `file:///var/index.html`, which might not be what was intended.
|
|
|
///
|
|
///
|
|
|
/// (Note that `Path::new` removes any trailing slash.)
|
|
/// (Note that `Path::new` removes any trailing slash.)
|
|
|
- pub fn from_directory_path<P: AsPath>(path: P) -> Result<Url, ()> {
|
|
|
|
|
- let mut path = try!(path_to_file_url_path(path.as_path()));
|
|
|
|
|
|
|
+ pub fn from_directory_path<P: AsRef<Path>>(path: P) -> Result<Url, ()> {
|
|
|
|
|
+ let mut path = try!(path_to_file_url_path(path.as_ref()));
|
|
|
// Add an empty path component (i.e. a trailing slash in serialization)
|
|
// Add an empty path component (i.e. a trailing slash in serialization)
|
|
|
// so that the entire path is used as a base URL.
|
|
// so that the entire path is used as a base URL.
|
|
|
path.push("".to_string());
|
|
path.push("".to_string());
|
|
@@ -974,15 +975,15 @@ fn file_url_path_to_pathbuf(path: &[String]) -> Result<PathBuf, ()> {
|
|
|
use std::path::PathBuf;
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
if path.is_empty() {
|
|
if path.is_empty() {
|
|
|
- return Ok(PathBuf::new("/"))
|
|
|
|
|
|
|
+ return Ok(PathBuf::from("/"))
|
|
|
}
|
|
}
|
|
|
let mut bytes = Vec::new();
|
|
let mut bytes = Vec::new();
|
|
|
for path_part in path.iter() {
|
|
for path_part in path.iter() {
|
|
|
bytes.push(b'/');
|
|
bytes.push(b'/');
|
|
|
percent_decode_to(path_part.as_bytes(), &mut bytes);
|
|
percent_decode_to(path_part.as_bytes(), &mut bytes);
|
|
|
}
|
|
}
|
|
|
- let os_str = <OsStr as OsStrExt>::from_bytes(&bytes);
|
|
|
|
|
- let path = PathBuf::new(&os_str);
|
|
|
|
|
|
|
+ let os_str = OsStr::from_bytes(&bytes);
|
|
|
|
|
+ let path = PathBuf::from(os_str);
|
|
|
debug_assert!(path.is_absolute(),
|
|
debug_assert!(path.is_absolute(),
|
|
|
"to_file_path() failed to produce an absolute Path");
|
|
"to_file_path() failed to produce an absolute Path");
|
|
|
Ok(path)
|
|
Ok(path)
|
|
@@ -1008,7 +1009,7 @@ fn file_url_path_to_pathbuf(path: &[String]) -> Result<PathBuf, ()> {
|
|
|
Err(..) => return Err(()),
|
|
Err(..) => return Err(()),
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- let path = PathBuf::new(&string);
|
|
|
|
|
|
|
+ let path = PathBuf::from(string);
|
|
|
debug_assert!(path.is_absolute(),
|
|
debug_assert!(path.is_absolute(),
|
|
|
"to_file_path() failed to produce an absolute Path");
|
|
"to_file_path() failed to produce an absolute Path");
|
|
|
Ok(path)
|
|
Ok(path)
|