Skip to content

Commit 0c03b92

Browse files
committed
Implemented Path::iter
1 parent 5d87006 commit 0c03b92

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/path/path.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::ffi::OsStr;
22

3-
use crate::path::{Ancestors, Components, Display, PathBuf};
3+
use crate::path::{Ancestors, Components, Display, Iter, PathBuf};
44
use crate::{fs, io};
55

66
/// This struct is an async version of [`std::path::Path`].
@@ -390,6 +390,31 @@ impl Path {
390390
self.inner.is_relative()
391391
}
392392

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+
393418
/// Queries the file system to get information about a file, directory, etc.
394419
///
395420
/// This function will traverse symbolic links to query information about the

0 commit comments

Comments
 (0)