From 1bd17f11f2809a1132fea2469af5b03437ecafe9 Mon Sep 17 00:00:00 2001 From: Wouter Geraedts Date: Sun, 13 Oct 2019 21:04:47 +0200 Subject: [PATCH] Implemented PathBuf::as_path --- src/path/pathbuf.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/path/pathbuf.rs b/src/path/pathbuf.rs index 2f33328..59f2746 100644 --- a/src/path/pathbuf.rs +++ b/src/path/pathbuf.rs @@ -10,6 +10,24 @@ pub struct PathBuf { inner: std::path::PathBuf, } +impl PathBuf { + /// Coerces to a [`Path`] slice. + /// + /// [`Path`]: struct.Path.html + /// + /// # Examples + /// + /// ``` + /// use async_std::path::{Path, PathBuf}; + /// + /// let p = PathBuf::from("/test"); + /// assert_eq!(Path::new("/test"), p.as_path()); + /// ``` + pub fn as_path(&self) -> &Path { + self.inner.as_path().into() + } +} + impl From for PathBuf { fn from(path: std::path::PathBuf) -> PathBuf { PathBuf { inner: path }