Struct std::path::Components
[−]
[src]
pub struct Components<'a> { // some fields omitted }
The core iterator giving the components of a path.
See the module documentation for an in-depth explanation of components and their role in the API.
Examples
fn main() { use std::path::Path; let path = Path::new("/tmp/foo/bar.txt"); for component in path.components() { println!("{:?}", component); } }use std::path::Path; let path = Path::new("/tmp/foo/bar.txt"); for component in path.components() { println!("{:?}", component); }
Methods
impl<'a> Components<'a>
fn as_path(&self) -> &'a Path
Extracts a slice corresponding to the portion of the path remaining for iteration.
Examples
fn main() { use std::path::Path; let mut components = Path::new("/tmp/foo/bar.txt").components(); components.next(); components.next(); assert_eq!(Path::new("foo/bar.txt"), components.as_path()); }use std::path::Path; let mut components = Path::new("/tmp/foo/bar.txt").components(); components.next(); components.next(); assert_eq!(Path::new("foo/bar.txt"), components.as_path());
fn peek(&self) -> Option<Component<'a>>
Deprecated since 1.6.0
: use peekable() instead
Examine the next component without consuming it.