about summary refs log tree commit diff
path: root/src/libstd/path.rs
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-03-16 21:56:52 -0400
committerGitHub <noreply@github.com>2017-03-16 21:56:52 -0400
commitbc6eecd0c2ed7854d52fc823be0b093f3bc76ba8 (patch)
treeba624a9e66a33fec8bcc8bc93734d03acbdd6688 /src/libstd/path.rs
parent6adbbfc6ba8786ea91e1051ea14d64a91839f5b5 (diff)
parent0aeb9c12979e6da753701a798d04105b6b1a8c28 (diff)
downloadrust-bc6eecd0c2ed7854d52fc823be0b093f3bc76ba8.tar.gz
rust-bc6eecd0c2ed7854d52fc823be0b093f3bc76ba8.zip
Merge branch 'master' into frewsxcv-osstr
Diffstat (limited to 'src/libstd/path.rs')
-rw-r--r--src/libstd/path.rs34
1 files changed, 27 insertions, 7 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index 245a6d945b5..49b01bc0853 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -1196,7 +1196,7 @@ impl PathBuf {
     }
 
     /// Converts this `PathBuf` into a boxed `Path`.
-    #[unstable(feature = "into_boxed_path", issue = "0")]
+    #[unstable(feature = "into_boxed_path", issue = "40380")]
     pub fn into_boxed_path(self) -> Box<Path> {
         unsafe { mem::transmute(self.inner.into_boxed_os_str()) }
     }
@@ -1210,6 +1210,20 @@ impl<'a> From<&'a Path> for Box<Path> {
     }
 }
 
+#[stable(feature = "path_buf_from_box", since = "1.17.0")]
+impl<'a> From<Box<Path>> for PathBuf {
+    fn from(boxed: Box<Path>) -> PathBuf {
+        boxed.into_path_buf()
+    }
+}
+
+#[stable(feature = "box_from_path_buf", since = "1.17.0")]
+impl Into<Box<Path>> for PathBuf {
+    fn into(self) -> Box<Path> {
+        self.into_boxed_path()
+    }
+}
+
 #[stable(feature = "box_default_extra", since = "1.17.0")]
 impl Default for Box<Path> {
     fn default() -> Box<Path> {
@@ -2089,6 +2103,13 @@ impl Path {
     pub fn is_dir(&self) -> bool {
         fs::metadata(self).map(|m| m.is_dir()).unwrap_or(false)
     }
+
+    /// Converts a `Box<Path>` into a `PathBuf` without copying or allocating.
+    #[unstable(feature = "into_boxed_path", issue = "40380")]
+    pub fn into_path_buf(self: Box<Path>) -> PathBuf {
+        let inner: Box<OsStr> = unsafe { mem::transmute(self) };
+        PathBuf { inner: OsString::from(inner) }
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -3703,12 +3724,11 @@ mod tests {
     fn into_boxed() {
         let orig: &str = "some/sort/of/path";
         let path = Path::new(orig);
-        let path_buf = path.to_owned();
-        let box1: Box<Path> = Box::from(path);
-        let box2 = path_buf.into_boxed_path();
-        assert_eq!(path, &*box1);
-        assert_eq!(box1, box2);
-        assert_eq!(&*box2, path);
+        let boxed: Box<Path> = Box::from(path);
+        let path_buf = path.to_owned().into_boxed_path().into_path_buf();
+        assert_eq!(path, &*boxed);
+        assert_eq!(&*boxed, &*path_buf);
+        assert_eq!(&*path_buf, path);
     }
 
     #[test]