Skip to content

Commit 6bbfd03

Browse files
committed
Fixed various tests
1 parent e690b55 commit 6bbfd03

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

src/path/path.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::{fs, io};
66
/// This struct is an async version of [`std::path::Path`].
77
///
88
/// [`std::path::Path`]: https://doc.rust-lang.org/std/path/struct.Path.html
9+
#[derive(Debug, PartialEq)]
910
pub struct Path {
1011
inner: std::path::Path,
1112
}
@@ -28,10 +29,14 @@ impl Path {
2829
/// # Examples
2930
///
3031
/// ```no_run
32+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
33+
/// #
3134
/// use async_std::path::{Path, PathBuf};
3235
///
3336
/// let path = Path::new("/foo/test/../test/bar.rs");
34-
/// assert_eq!(path.canonicalize().unwrap(), PathBuf::from("/foo/test/bar.rs"));
37+
/// assert_eq!(path.canonicalize().await.unwrap(), PathBuf::from("/foo/test/bar.rs"));
38+
/// #
39+
/// # Ok(()) }) }
3540
/// ```
3641
pub async fn canonicalize(&self) -> io::Result<PathBuf> {
3742
fs::canonicalize(self).await
@@ -86,8 +91,12 @@ impl Path {
8691
/// # Examples
8792
///
8893
/// ```no_run
94+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
95+
/// #
8996
/// use async_std::path::Path;
90-
/// assert_eq!(Path::new("does_not_exist.txt").exists(), false);
97+
/// assert_eq!(Path::new("does_not_exist.txt").exists().await, false);
98+
/// #
99+
/// # Ok(()) }) }
91100
/// ```
92101
///
93102
/// # See Also
@@ -155,14 +164,26 @@ impl<'a> Into<&'a std::path::Path> for &'a Path {
155164
}
156165
}
157166

167+
impl AsRef<OsStr> for Path {
168+
fn as_ref(&self) -> &OsStr {
169+
self.inner.as_ref()
170+
}
171+
}
172+
158173
impl AsRef<Path> for Path {
159174
fn as_ref(&self) -> &Path {
160175
self
161176
}
162177
}
163178

164-
impl std::fmt::Debug for Path {
165-
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
166-
std::fmt::Debug::fmt(&self.inner, formatter)
179+
impl AsRef<Path> for OsStr {
180+
fn as_ref(&self) -> &Path {
181+
Path::new(self)
167182
}
168183
}
184+
185+
impl AsRef<Path> for str {
186+
fn as_ref(&self) -> &Path {
187+
Path::new(self)
188+
}
189+
}

src/path/pathbuf.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::path::Path;
55
/// This struct is an async version of [`std::path::PathBuf`].
66
///
77
/// [`std::path::Path`]: https://doc.rust-lang.org/std/path/struct.PathBuf.html
8+
#[derive(Debug, PartialEq)]
89
pub struct PathBuf {
910
inner: std::path::PathBuf,
1011
}
@@ -23,20 +24,18 @@ impl Into<std::path::PathBuf> for PathBuf {
2324

2425
impl From<OsString> for PathBuf {
2526
fn from(path: OsString) -> PathBuf {
26-
PathBuf {
27-
inner: std::path::PathBuf::from(path),
28-
}
27+
std::path::PathBuf::from(path).into()
2928
}
3029
}
3130

32-
impl AsRef<Path> for PathBuf {
33-
fn as_ref(&self) -> &Path {
34-
Path::new(&self.inner)
31+
impl From<&str> for PathBuf {
32+
fn from(path: &str) -> PathBuf {
33+
std::path::PathBuf::from(path).into()
3534
}
3635
}
3736

38-
impl std::fmt::Debug for PathBuf {
39-
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40-
std::fmt::Debug::fmt(&self.inner, formatter)
37+
impl AsRef<Path> for PathBuf {
38+
fn as_ref(&self) -> &Path {
39+
Path::new(&self.inner)
4140
}
4241
}

0 commit comments

Comments
 (0)