Skip to content

Commit a57ba7e

Browse files
committed
Implemented Path::into_path_buf
1 parent 6c6106a commit a57ba7e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/path/path.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ impl Path {
109109
fs::metadata(self).await.is_ok()
110110
}
111111

112+
/// Converts a [`Box<Path>`][`Box`] into a [`PathBuf`] without copying or
113+
/// allocating.
114+
///
115+
/// [`Box`]: https://doc.rust-lang.org/std/boxed/struct.Box.html
116+
/// [`PathBuf`]: struct.PathBuf.html
117+
pub fn into_path_buf(self: Box<Path>) -> PathBuf {
118+
let rw = Box::into_raw(self) as *mut std::path::Path;
119+
let inner = unsafe { Box::from_raw(rw) };
120+
inner.into_path_buf().into()
121+
}
122+
112123
/// Queries the file system to get information about a file, directory, etc.
113124
///
114125
/// This function will traverse symbolic links to query information about the

0 commit comments

Comments
 (0)