|
1 | 1 | use std::ffi::OsStr;
|
2 | 2 |
|
3 |
| -use crate::path::{Ancestors, Components, Display, PathBuf}; |
| 3 | +use crate::path::{Ancestors, Components, Display, Iter, PathBuf}; |
4 | 4 | use crate::{fs, io};
|
5 | 5 |
|
6 | 6 | /// This struct is an async version of [`std::path::Path`].
|
@@ -390,6 +390,31 @@ impl Path {
|
390 | 390 | self.inner.is_relative()
|
391 | 391 | }
|
392 | 392 |
|
| 393 | + /// Produces an iterator over the path's components viewed as [`OsStr`] |
| 394 | + /// slices. |
| 395 | + /// |
| 396 | + /// For more information about the particulars of how the path is separated |
| 397 | + /// into components, see [`components`]. |
| 398 | + /// |
| 399 | + /// [`components`]: #method.components |
| 400 | + /// [`OsStr`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html |
| 401 | + /// |
| 402 | + /// # Examples |
| 403 | + /// |
| 404 | + /// ``` |
| 405 | + /// use async_std::path::{self, Path}; |
| 406 | + /// use std::ffi::OsStr; |
| 407 | + /// |
| 408 | + /// let mut it = Path::new("/tmp/foo.txt").iter(); |
| 409 | + /// assert_eq!(it.next(), Some(OsStr::new(&path::MAIN_SEPARATOR.to_string()))); |
| 410 | + /// assert_eq!(it.next(), Some(OsStr::new("tmp"))); |
| 411 | + /// assert_eq!(it.next(), Some(OsStr::new("foo.txt"))); |
| 412 | + /// assert_eq!(it.next(), None) |
| 413 | + /// ``` |
| 414 | + pub fn iter(&self) -> Iter<'_> { |
| 415 | + self.inner.iter() |
| 416 | + } |
| 417 | + |
393 | 418 | /// Queries the file system to get information about a file, directory, etc.
|
394 | 419 | ///
|
395 | 420 | /// This function will traverse symbolic links to query information about the
|
|
0 commit comments