Enum std::path::Component
pub enum Component<'a> {
    Prefix(PrefixComponent<'a>),
    RootDir,
    CurDir,
    ParentDir,
    Normal(&'a OsStr),
}
A single component of a path.
A Component roughly corresponds to a substring between path separators (/ or \).
This enum is created by iterating over Components, which in turn is created by the components method on Path.
Examples
use std::path::{Component, Path};
let path = Path::new("/tmp/foo/bar.txt");
let components = path.components().collect::<Vec<_>>();
assert_eq!(&components, &[
    Component::RootDir,
    Component::Normal("tmp".as_ref()),
    Component::Normal("foo".as_ref()),
    Component::Normal("bar.txt".as_ref()),
]);Variants
Prefix(PrefixComponent<'a>)
A Windows path prefix, e.g., C: or \\server\share.
There is a large variety of prefix types, see Prefix’s documentation for more.
Does not occur on Unix.
Tuple Fields of Prefix
0: PrefixComponent<'a>RootDir
The root directory component, appears after any prefix and before anything else.
It represents a separator that designates that a path starts from root.
CurDir
A reference to the current directory, i.e., ..
ParentDir
A reference to the parent directory, i.e., ...
Normal(&'a OsStr)
A normal component, e.g., a and b in a/b.
This variant is the most common one, it represents references to files or directories.
Tuple Fields of Normal
0: &'a OsStrImplementations
impl<'a> Component<'a>
pub fn as_os_str(self) -> &'a OsStr
Extracts the underlying OsStr slice.
Examples
use std::path::Path;
let path = Path::new("./tmp/foo/bar.txt");
let components: Vec<_> = path.components().map(|comp| comp.as_os_str()).collect();
assert_eq!(&components, &[".", "tmp", "foo", "bar.txt"]);Trait Implementations
impl AsRef<OsStr> for Component<'_>
fn as_ref(&self) -> &OsStr
Performs the conversion.
impl AsRef<Path> for Component<'_>
fn as_ref(&self) -> &Path
Performs the conversion.
impl<'a> Clone for Component<'a>
fn clone(&self) -> Component<'a>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
impl<'a> Debug for Component<'a>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter. Read more
impl<'a> Hash for Component<'a>
fn hash<__H: Hasher>(&self, state: &mut __H)
impl<'a> Ord for Component<'a>
fn cmp(&self, other: &Component<'a>) -> Ordering
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self
Restrict a value to a certain interval. Read more
impl<'a> PartialEq<Component<'a>> for Component<'a>
fn eq(&self, other: &Component<'a>) -> bool
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Component<'a>) -> bool
This method tests for !=.
impl<'a> PartialOrd<Component<'a>> for Component<'a>
fn partial_cmp(&self, other: &Component<'a>) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for self and other) and is used by the > operator. Read more
fn ge(&self, other: &Rhs) -> bool
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
impl<'a> Copy for Component<'a>
impl<'a> Eq for Component<'a>
impl<'a> StructuralEq for Component<'a>
impl<'a> StructuralPartialEq for Component<'a>
Auto Trait Implementations
impl<'a> RefUnwindSafe for Component<'a>
impl<'a> Send for Component<'a>
impl<'a> Sync for Component<'a>
impl<'a> Unpin for Component<'a>
impl<'a> UnwindSafe for Component<'a>
Blanket Implementations
impl<T> From<T> for T
pub fn from(t: T) -> T
Performs the conversion.
pub fn into(self) -> U
Performs the conversion.
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
toowned_clone_into #41263)recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
    © 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
    https://doc.rust-lang.org/std/path/enum.Component.html