@@ -6,6 +6,7 @@ use crate::{fs, io};
6
6
/// This struct is an async version of [`std::path::Path`].
7
7
///
8
8
/// [`std::path::Path`]: https://doc.rust-lang.org/std/path/struct.Path.html
9
+ #[ derive( Debug , PartialEq ) ]
9
10
pub struct Path {
10
11
inner : std:: path:: Path ,
11
12
}
@@ -28,10 +29,14 @@ impl Path {
28
29
/// # Examples
29
30
///
30
31
/// ```no_run
32
+ /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
33
+ /// #
31
34
/// use async_std::path::{Path, PathBuf};
32
35
///
33
36
/// 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(()) }) }
35
40
/// ```
36
41
pub async fn canonicalize ( & self ) -> io:: Result < PathBuf > {
37
42
fs:: canonicalize ( self ) . await
@@ -86,8 +91,12 @@ impl Path {
86
91
/// # Examples
87
92
///
88
93
/// ```no_run
94
+ /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
95
+ /// #
89
96
/// 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(()) }) }
91
100
/// ```
92
101
///
93
102
/// # See Also
@@ -155,14 +164,26 @@ impl<'a> Into<&'a std::path::Path> for &'a Path {
155
164
}
156
165
}
157
166
167
+ impl AsRef < OsStr > for Path {
168
+ fn as_ref ( & self ) -> & OsStr {
169
+ self . inner . as_ref ( )
170
+ }
171
+ }
172
+
158
173
impl AsRef < Path > for Path {
159
174
fn as_ref ( & self ) -> & Path {
160
175
self
161
176
}
162
177
}
163
178
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 )
167
182
}
168
183
}
184
+
185
+ impl AsRef < Path > for str {
186
+ fn as_ref ( & self ) -> & Path {
187
+ Path :: new ( self )
188
+ }
189
+ }
0 commit comments