Struct Components

#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct Components<'a> { pub(in ::path) path: &'a [u8], pub(in ::path) prefix: Option<Prefix<'a>>, pub(in ::path) has_physical_root: bool, pub(in ::path) front: State, pub(in ::path) back: State }

An iterator over the Components of a Path.

This struct is created by the components method on Path. See its documentation for more.

Examples

use std::path::Path;

let path = Path::new("/tmp/foo/bar.txt");

for component in path.components() {
    println!("{component:?}");
}

Fields

path: &'a [u8]
prefix: Option<Prefix<'a>>
has_physical_root: bool
front: State
back: State

Implementations

impl<'a> Components<'a>

fn prefix_len(&self) -> usize
fn prefix_verbatim(&self) -> bool
fn prefix_remaining(&self) -> usize

how much of the prefix is left from the point of view of iteration?

fn len_before_body(&self) -> usize
fn finished(&self) -> bool
fn is_sep_byte(&self, b: u8) -> bool
fn as_path(&self) -> &'a Path

Extracts a slice corresponding to the portion of the path remaining for iteration.

Examples

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 has_root(&self) -> bool

Is the original path rooted?

fn include_cur_dir(&self) -> bool

Should the normalized path include a leading . ?

unsafe fn parse_single_component<'b>(&self, comp: &'b [u8]) -> Option<Component<'b>>
fn parse_next_component(&self) -> (usize, Option<Component<'a>>)
fn parse_next_component_back(&self) -> (usize, Option<Component<'a>>)
fn trim_left(&mut self)
fn trim_right(&mut self)

Trait Implementations

impl AsRef<OsStr> for Components<'_>

fn as_ref(&self) -> &OsStr

impl AsRef<Path> for Components<'_>

fn as_ref(&self) -> &Path

impl Debug for Components<'_>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Eq for Components<'_>

impl FusedIterator for Components<'_>

impl Ord for Components<'_>

fn cmp(&self, other: &Self) -> Ordering

impl<'a> Clone for Components<'a>

fn clone(&self) -> Components<'a>

impl<'a> DoubleEndedIterator for Components<'a>

fn next_back(&mut self) -> Option<Component<'a>>

impl<'a> Iterator for Components<'a>

type Item = Component<'a>;
fn next(&mut self) -> Option<Component<'a>>

impl<'a> PartialEq for Components<'a>

fn eq(&self, other: &Components<'a>) -> bool

impl<'a> PartialOrd for Components<'a>

fn partial_cmp(&self, other: &Components<'a>) -> Option<Ordering>

Auto Trait Implementations

impl<'a> Freeze for Components<'a>

impl<'a> RefUnwindSafe for Components<'a>

impl<'a> Send for Components<'a>

impl<'a> Sync for Components<'a>

impl<'a> Unpin for Components<'a>

impl<'a> UnsafeUnpin for Components<'a>

impl<'a> UnwindSafe for Components<'a>

Blanket Implementations

impl<I> IntoIterator for Components<'a> where I: Iterator,

type Item = <I as Iterator>::Item;
type IntoIter = I;
fn into_iter(self) -> I

impl<T> Any for Components<'a> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Components<'a> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Components<'a> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for Components<'a> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for Components<'a>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for Components<'a> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for Components<'a>

impl<T> ToOwned for Components<'a> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for Components<'a> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for Components<'a> where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for Components<'a> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>