From a57ba7ece0f99936e011774833470963604b093b Mon Sep 17 00:00:00 2001 From: Wouter Geraedts Date: Sun, 13 Oct 2019 18:49:52 +0200 Subject: [PATCH] Implemented Path::into_path_buf --- src/path/path.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/path/path.rs b/src/path/path.rs index ffe80d94..32e59b20 100644 --- a/src/path/path.rs +++ b/src/path/path.rs @@ -109,6 +109,17 @@ impl Path { fs::metadata(self).await.is_ok() } + /// Converts a [`Box`][`Box`] into a [`PathBuf`] without copying or + /// allocating. + /// + /// [`Box`]: https://doc.rust-lang.org/std/boxed/struct.Box.html + /// [`PathBuf`]: struct.PathBuf.html + pub fn into_path_buf(self: Box) -> PathBuf { + let rw = Box::into_raw(self) as *mut std::path::Path; + let inner = unsafe { Box::from_raw(rw) }; + inner.into_path_buf().into() + } + /// Queries the file system to get information about a file, directory, etc. /// /// This function will traverse symbolic links to query information about the