diff --git a/src/path/path.rs b/src/path/path.rs index e7353e9..196935a 100644 --- a/src/path/path.rs +++ b/src/path/path.rs @@ -6,6 +6,7 @@ use crate::{fs, io}; /// This struct is an async version of [`std::path::Path`]. /// /// [`std::path::Path`]: https://doc.rust-lang.org/std/path/struct.Path.html +#[derive(Debug, PartialEq)] pub struct Path { inner: std::path::Path, } @@ -28,10 +29,14 @@ impl Path { /// # Examples /// /// ```no_run + /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # /// use async_std::path::{Path, PathBuf}; /// /// let path = Path::new("/foo/test/../test/bar.rs"); - /// assert_eq!(path.canonicalize().unwrap(), PathBuf::from("/foo/test/bar.rs")); + /// assert_eq!(path.canonicalize().await.unwrap(), PathBuf::from("/foo/test/bar.rs")); + /// # + /// # Ok(()) }) } /// ``` pub async fn canonicalize(&self) -> io::Result { fs::canonicalize(self).await @@ -86,8 +91,12 @@ impl Path { /// # Examples /// /// ```no_run + /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # /// use async_std::path::Path; - /// assert_eq!(Path::new("does_not_exist.txt").exists(), false); + /// assert_eq!(Path::new("does_not_exist.txt").exists().await, false); + /// # + /// # Ok(()) }) } /// ``` /// /// # See Also @@ -155,14 +164,26 @@ impl<'a> Into<&'a std::path::Path> for &'a Path { } } +impl AsRef for Path { + fn as_ref(&self) -> &OsStr { + self.inner.as_ref() + } +} + impl AsRef for Path { fn as_ref(&self) -> &Path { self } } -impl std::fmt::Debug for Path { - fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Debug::fmt(&self.inner, formatter) +impl AsRef for OsStr { + fn as_ref(&self) -> &Path { + Path::new(self) } } + +impl AsRef for str { + fn as_ref(&self) -> &Path { + Path::new(self) + } +} \ No newline at end of file diff --git a/src/path/pathbuf.rs b/src/path/pathbuf.rs index c3665e9..308200e 100644 --- a/src/path/pathbuf.rs +++ b/src/path/pathbuf.rs @@ -5,6 +5,7 @@ use crate::path::Path; /// This struct is an async version of [`std::path::PathBuf`]. /// /// [`std::path::Path`]: https://doc.rust-lang.org/std/path/struct.PathBuf.html +#[derive(Debug, PartialEq)] pub struct PathBuf { inner: std::path::PathBuf, } @@ -23,20 +24,18 @@ impl Into for PathBuf { impl From for PathBuf { fn from(path: OsString) -> PathBuf { - PathBuf { - inner: std::path::PathBuf::from(path), - } + std::path::PathBuf::from(path).into() } } -impl AsRef for PathBuf { - fn as_ref(&self) -> &Path { - Path::new(&self.inner) +impl From<&str> for PathBuf { + fn from(path: &str) -> PathBuf { + std::path::PathBuf::from(path).into() } } -impl std::fmt::Debug for PathBuf { - fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Debug::fmt(&self.inner, formatter) +impl AsRef for PathBuf { + fn as_ref(&self) -> &Path { + Path::new(&self.inner) } }