pub enum Component<'a> {
Prefix(PrefixComponent<'a>),
RootDir,
CurDir,
ParentDir,
Normal(&'a OsStr),
}Expand description
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.
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.
Implementations§
Trait Implementations§
Source§impl<'a> Arg for Component<'a>
Available on crate feature std only.
impl<'a> Arg for Component<'a>
std only.Source§fn to_string_lossy(&self) -> Cow<'_, str>
fn to_string_lossy(&self) -> Cow<'_, str>
Cow<'_, str>.Source§fn as_cow_c_str(&self) -> Result<Cow<'_, CStr>, Errno>
fn as_cow_c_str(&self) -> Result<Cow<'_, CStr>, Errno>
CStr.impl<'a> Copy for Component<'a>
impl<'a> Eq for Component<'a>
1.0.0 · Source§impl<'a> Ord for Component<'a>
impl<'a> Ord for Component<'a>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.0.0 · Source§impl<'a> PartialOrd for Component<'a>
impl<'a> PartialOrd for Component<'a>
impl<'a> StructuralPartialEq for Component<'a>
Source§impl<'a> TryFrom<Component<'a>> for UnixComponent<'a>
Available on crate feature std only.
impl<'a> TryFrom<Component<'a>> for UnixComponent<'a>
std only.Source§fn try_from(
component: Component<'a>,
) -> Result<UnixComponent<'a>, <UnixComponent<'a> as TryFrom<Component<'a>>>::Error>
fn try_from( component: Component<'a>, ) -> Result<UnixComponent<'a>, <UnixComponent<'a> as TryFrom<Component<'a>>>::Error>
Attempts to convert a std::path::Component into a UnixComponent, returning a result
containing the new component when successful or the original component when failed
§Examples
use std::convert::TryFrom;
use std::ffi::OsStr;
use std::path::Component;
use typed_path::UnixComponent;
let component = UnixComponent::try_from(Component::RootDir).unwrap();
assert_eq!(component, UnixComponent::RootDir);
let component = UnixComponent::try_from(Component::CurDir).unwrap();
assert_eq!(component, UnixComponent::CurDir);
let component = UnixComponent::try_from(Component::ParentDir).unwrap();
assert_eq!(component, UnixComponent::ParentDir);
let component = UnixComponent::try_from(Component::Normal(OsStr::new("file.txt"))).unwrap();
assert_eq!(component, UnixComponent::Normal(b"file.txt"));Source§impl<'a> TryFrom<Component<'a>> for WindowsComponent<'a>
Available on crate feature std only.
impl<'a> TryFrom<Component<'a>> for WindowsComponent<'a>
std only.Source§fn try_from(
component: Component<'a>,
) -> Result<WindowsComponent<'a>, <WindowsComponent<'a> as TryFrom<Component<'a>>>::Error>
fn try_from( component: Component<'a>, ) -> Result<WindowsComponent<'a>, <WindowsComponent<'a> as TryFrom<Component<'a>>>::Error>
Attempts to convert a std::path::Component into a WindowsComponent, returning a
result containing the new component when successful or the original component when failed
§Examples
use std::convert::TryFrom;
use std::ffi::OsStr;
use std::path::Component;
use typed_path::WindowsComponent;
let component = WindowsComponent::try_from(Component::RootDir).unwrap();
assert_eq!(component, WindowsComponent::RootDir);
let component = WindowsComponent::try_from(Component::CurDir).unwrap();
assert_eq!(component, WindowsComponent::CurDir);
let component = WindowsComponent::try_from(Component::ParentDir).unwrap();
assert_eq!(component, WindowsComponent::ParentDir);
let component = WindowsComponent::try_from(Component::Normal(OsStr::new("file.txt"))).unwrap();
assert_eq!(component, WindowsComponent::Normal(b"file.txt"));Alongside the traditional path components, the Component::Prefix variant is also
supported, but only when compiling on Windows. When on a non-Windows platform, the
conversion will always fail.
Source§impl<'a> TryFrom<UnixComponent<'a>> for Component<'a>
Available on crate feature std only.
impl<'a> TryFrom<UnixComponent<'a>> for Component<'a>
std only.Source§fn try_from(
component: UnixComponent<'a>,
) -> Result<Component<'a>, <Component<'a> as TryFrom<UnixComponent<'a>>>::Error>
fn try_from( component: UnixComponent<'a>, ) -> Result<Component<'a>, <Component<'a> as TryFrom<UnixComponent<'a>>>::Error>
Attempts to convert a UnixComponent into a std::path::Component, returning a result
containing the new path when successful or the original path when failed
§Examples
use std::convert::TryFrom;
use std::ffi::OsStr;
use std::path::Component;
use typed_path::UnixComponent;
let component = Component::try_from(UnixComponent::RootDir).unwrap();
assert_eq!(component, Component::RootDir);
let component = Component::try_from(UnixComponent::CurDir).unwrap();
assert_eq!(component, Component::CurDir);
let component = Component::try_from(UnixComponent::ParentDir).unwrap();
assert_eq!(component, Component::ParentDir);
let component = Component::try_from(UnixComponent::Normal(b"file.txt")).unwrap();
assert_eq!(component, Component::Normal(OsStr::new("file.txt")));Source§type Error = UnixComponent<'a>
type Error = UnixComponent<'a>
Source§impl<'a> TryFrom<WindowsComponent<'a>> for Component<'a>
Available on crate feature std only.
impl<'a> TryFrom<WindowsComponent<'a>> for Component<'a>
std only.Source§fn try_from(
component: WindowsComponent<'a>,
) -> Result<Component<'a>, <Component<'a> as TryFrom<WindowsComponent<'a>>>::Error>
fn try_from( component: WindowsComponent<'a>, ) -> Result<Component<'a>, <Component<'a> as TryFrom<WindowsComponent<'a>>>::Error>
Attempts to convert a WindowsComponent into a std::path::Component, returning a
result containing the new path when successful or the original path when failed
§Examples
use std::convert::TryFrom;
use std::ffi::OsStr;
use std::path::Component;
use typed_path::WindowsComponent;
let component = Component::try_from(WindowsComponent::RootDir).unwrap();
assert_eq!(component, Component::RootDir);
let component = Component::try_from(WindowsComponent::CurDir).unwrap();
assert_eq!(component, Component::CurDir);
let component = Component::try_from(WindowsComponent::ParentDir).unwrap();
assert_eq!(component, Component::ParentDir);
let component = Component::try_from(WindowsComponent::Normal(b"file.txt")).unwrap();
assert_eq!(component, Component::Normal(OsStr::new("file.txt")));Alongside the traditional path components, the Component::Prefix variant is also
supported, but only when compiling on Windows. When on a non-Windows platform, the
conversion will always fail.
Source§type Error = WindowsComponent<'a>
type Error = WindowsComponent<'a>
Auto Trait Implementations§
impl<'a> Freeze for Component<'a>
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> UnsafeUnpin for Component<'a>
impl<'a> UnwindSafe for Component<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more