Implemented Path::iter

yoshuawuyts-patch-1
Wouter Geraedts 5 years ago
parent 5d87006006
commit 0c03b92373

@ -1,6 +1,6 @@
use std::ffi::OsStr;
use crate::path::{Ancestors, Components, Display, PathBuf};
use crate::path::{Ancestors, Components, Display, Iter, PathBuf};
use crate::{fs, io};
/// This struct is an async version of [`std::path::Path`].
@ -390,6 +390,31 @@ impl Path {
self.inner.is_relative()
}
/// Produces an iterator over the path's components viewed as [`OsStr`]
/// slices.
///
/// For more information about the particulars of how the path is separated
/// into components, see [`components`].
///
/// [`components`]: #method.components
/// [`OsStr`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html
///
/// # Examples
///
/// ```
/// use async_std::path::{self, Path};
/// use std::ffi::OsStr;
///
/// let mut it = Path::new("/tmp/foo.txt").iter();
/// assert_eq!(it.next(), Some(OsStr::new(&path::MAIN_SEPARATOR.to_string())));
/// assert_eq!(it.next(), Some(OsStr::new("tmp")));
/// assert_eq!(it.next(), Some(OsStr::new("foo.txt")));
/// assert_eq!(it.next(), None)
/// ```
pub fn iter(&self) -> Iter<'_> {
self.inner.iter()
}
/// Queries the file system to get information about a file, directory, etc.
///
/// This function will traverse symbolic links to query information about the

Loading…
Cancel
Save