Răsfoiți Sursa

Update to rust master

Alex Crichton 11 ani în urmă
părinte
comite
8e356fe493
2 a modificat fișierele cu 16 adăugiri și 15 ștergeri
  1. 12 11
      src/lib.rs
  2. 4 4
      src/tests.rs

+ 12 - 11
src/lib.rs

@@ -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]
 extern crate matches;
 
 use std::fmt::{self, Formatter};
 use std::hash;
-use std::path::{Path, PathBuf, AsPath};
+use std::path::{Path, PathBuf};
 
 pub use host::{Host, Ipv6Address};
 pub use parser::{ErrorHandler, ParseResult, ParseError};
@@ -479,8 +480,8 @@ impl Url {
     ///
     /// 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:`).
-    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))
     }
 
@@ -501,8 +502,8 @@ impl Url {
     ///   as the base URL is `file:///var/index.html`, which might not be what was intended.
     ///
     /// (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)
         // so that the entire path is used as a base URL.
         path.push("".to_string());
@@ -974,15 +975,15 @@ fn file_url_path_to_pathbuf(path: &[String]) -> Result<PathBuf, ()> {
     use std::path::PathBuf;
 
     if path.is_empty() {
-        return Ok(PathBuf::new("/"))
+        return Ok(PathBuf::from("/"))
     }
     let mut bytes = Vec::new();
     for path_part in path.iter() {
         bytes.push(b'/');
         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(),
                   "to_file_path() failed to produce an absolute Path");
     Ok(path)
@@ -1008,7 +1009,7 @@ fn file_url_path_to_pathbuf(path: &[String]) -> Result<PathBuf, ()> {
             Err(..) => return Err(()),
         }
     }
-    let path = PathBuf::new(&string);
+    let path = PathBuf::from(string);
     debug_assert!(path.is_absolute(),
                   "to_file_path() failed to produce an absolute Path");
     Ok(path)

+ 4 - 4
src/tests.rs

@@ -214,7 +214,7 @@ fn new_file_paths() {
         let mut url = Url::from_file_path(Path::new("/foo/bar")).unwrap();
         assert_eq!(url.host(), Some(&Host::Domain("".to_string())));
         assert_eq!(url.path(), Some(&["foo".to_string(), "bar".to_string()][..]));
-        assert!(url.to_file_path() == Ok(PathBuf::new("/foo/bar")));
+        assert!(url.to_file_path() == Ok(PathBuf::from("/foo/bar")));
 
         url.path_mut().unwrap()[1] = "ba\0r".to_string();
         url.to_file_path().is_ok();
@@ -232,8 +232,8 @@ fn new_path_bad_utf8() {
     use std::path::{Path, PathBuf};
 
     let url = Url::from_file_path(Path::new("/foo/ba%80r")).unwrap();
-    let os_str = <OsStr as OsStrExt>::from_bytes(b"/foo/ba\x80r");
-    assert_eq!(url.to_file_path(), Ok(PathBuf::new(&os_str)));
+    let os_str = OsStr::from_bytes(b"/foo/ba\x80r");
+    assert_eq!(url.to_file_path(), Ok(PathBuf::from(os_str)));
 }
 
 #[test]
@@ -244,7 +244,7 @@ fn new_path_windows_fun() {
     assert_eq!(url.host(), Some(&Host::Domain("".to_string())));
     assert_eq!(url.path(), Some(&["C:".to_string(), "foo".to_string(), "bar".to_string()][..]));
     assert_eq!(url.to_file_path(),
-               Ok(PathBuf::new(r"C:\foo\bar")));
+               Ok(PathBuf::from(r"C:\foo\bar")));
 
     url.path_mut().unwrap()[2] = "ba\0r".to_string();
     assert!(url.to_file_path().is_ok());