Enum typed_path::windows::WindowsComponent
source · [−]pub enum WindowsComponent<'a> {
Prefix(WindowsPrefixComponent<'a>),
RootDir,
CurDir,
ParentDir,
Normal(&'a [u8]),
}
Expand description
Byte slice version of std::path::Component
that represents a Windows-specific component
Variants
Prefix(WindowsPrefixComponent<'a>)
RootDir
CurDir
ParentDir
Normal(&'a [u8])
Implementations
sourceimpl<'a> WindowsComponent<'a>
impl<'a> WindowsComponent<'a>
sourcepub fn as_path<T>(&self) -> &Path<T> where
T: for<'enc> Encoding<'enc>,
pub fn as_path<T>(&self) -> &Path<T> where
T: for<'enc> Encoding<'enc>,
Returns path representing this specific component
sourcepub fn prefix(self) -> Option<WindowsPrefixComponent<'a>>
pub fn prefix(self) -> Option<WindowsPrefixComponent<'a>>
Converts from WindowsComponent
to Option<WindowsPrefixComponent>
Converts self
into an Option<WindowsPrefixComponent>
, consuming self
, and
discarding if not a WindowsPrefixComponent
sourcepub fn prefix_kind(self) -> Option<WindowsPrefix<'a>>
pub fn prefix_kind(self) -> Option<WindowsPrefix<'a>>
Converts from WindowsComponent
to Option<WindowsPrefix>
Converts self
into an Option<WindowsPrefix>
, consuming self
, and
discarding if not a WindowsPrefixComponent
whose kind
method we invoke
Trait Implementations
sourceimpl AsRef<[u8]> for WindowsComponent<'_>
impl AsRef<[u8]> for WindowsComponent<'_>
sourceimpl<T> AsRef<Path<T>> for WindowsComponent<'_> where
T: for<'enc> Encoding<'enc>,
impl<T> AsRef<Path<T>> for WindowsComponent<'_> where
T: for<'enc> Encoding<'enc>,
sourceimpl<'a> Clone for WindowsComponent<'a>
impl<'a> Clone for WindowsComponent<'a>
sourcefn clone(&self) -> WindowsComponent<'a>
fn clone(&self) -> WindowsComponent<'a>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'a> Component<'a> for WindowsComponent<'a>
impl<'a> Component<'a> for WindowsComponent<'a>
sourcefn as_bytes(&self) -> &'a [u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
fn as_bytes(&self) -> &'a [u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
Extracts the underlying [[u8]
] slice
Examples
use typed_path::{Component, WindowsPath};
let path = WindowsPath::new(br"C:\tmp\foo\..\bar.txt");
let components: Vec<_> = path.components().map(|comp| comp.as_bytes()).collect();
assert_eq!(&components, &[
b"C:".as_slice(),
br"\".as_slice(),
b"tmp".as_slice(),
b"foo".as_slice(),
b"..".as_slice(),
b"bar.txt".as_slice(),
]);
sourcefn is_root(&self) -> bool
fn is_root(&self) -> bool
Root is one of two situations
- Is the root separator, e.g.
\windows
- Is a non-disk prefix, e.g.
\\server\share
Examples
use typed_path::{Component, windows::WindowsComponent};
use std::convert::TryFrom;
let root_dir = WindowsComponent::try_from(br"\").unwrap();
assert!(root_dir.is_root());
let non_disk_prefix = WindowsComponent::try_from(br"\\?\pictures").unwrap();
assert!(non_disk_prefix.is_root());
let disk_prefix = WindowsComponent::try_from(b"C:").unwrap();
assert!(!disk_prefix.is_root());
let normal = WindowsComponent::try_from(b"file.txt").unwrap();
assert!(!normal.is_root());
sourcefn is_normal(&self) -> bool
fn is_normal(&self) -> bool
Returns true if component is normal
Examples
use typed_path::{Component, windows::WindowsComponent};
use std::convert::TryFrom;
let normal = WindowsComponent::try_from(b"file.txt").unwrap();
assert!(normal.is_normal());
let root_dir = WindowsComponent::try_from(br"\").unwrap();
assert!(!root_dir.is_normal());
sourceimpl<'a> Debug for WindowsComponent<'a>
impl<'a> Debug for WindowsComponent<'a>
sourceimpl<'a> Hash for WindowsComponent<'a>
impl<'a> Hash for WindowsComponent<'a>
sourceimpl<'a> Ord for WindowsComponent<'a>
impl<'a> Ord for WindowsComponent<'a>
sourcefn cmp(&self, other: &WindowsComponent<'a>) -> Ordering
fn cmp(&self, other: &WindowsComponent<'a>) -> Ordering
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<'a> PartialEq<WindowsComponent<'a>> for WindowsComponent<'a>
impl<'a> PartialEq<WindowsComponent<'a>> for WindowsComponent<'a>
sourcefn eq(&self, other: &WindowsComponent<'a>) -> bool
fn eq(&self, other: &WindowsComponent<'a>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourceimpl<'a> PartialOrd<WindowsComponent<'a>> for WindowsComponent<'a>
impl<'a> PartialOrd<WindowsComponent<'a>> for WindowsComponent<'a>
sourcefn partial_cmp(&self, other: &WindowsComponent<'a>) -> Option<Ordering>
fn partial_cmp(&self, other: &WindowsComponent<'a>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
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
sourceimpl<'a> TryFrom<&'a [u8]> for WindowsComponent<'a>
impl<'a> TryFrom<&'a [u8]> for WindowsComponent<'a>
sourcefn try_from(path: &'a [u8]) -> Result<Self, Self::Error>
fn try_from(path: &'a [u8]) -> Result<Self, Self::Error>
Parses the byte slice into a WindowsComponent
Examples
use typed_path::windows::{WindowsComponent, WindowsPrefix};
use std::convert::TryFrom;
// Supports parsing Windows prefixes
let component = WindowsComponent::try_from(b"c:").unwrap();
assert_eq!(component.prefix_kind(), Some(WindowsPrefix::Disk(b'C')));
// Supports parsing standard windows path components
assert_eq!(WindowsComponent::try_from(br"\"), Ok(WindowsComponent::RootDir));
assert_eq!(WindowsComponent::try_from(b"."), Ok(WindowsComponent::CurDir));
assert_eq!(WindowsComponent::try_from(b".."), Ok(WindowsComponent::ParentDir));
assert_eq!(WindowsComponent::try_from(br"file.txt"), Ok(WindowsComponent::Normal(b"file.txt")));
assert_eq!(WindowsComponent::try_from(br"dir\"), Ok(WindowsComponent::Normal(b"dir")));
// Parsing more than one component will fail
assert!(WindowsComponent::try_from(br"\file").is_err());
sourceimpl<'a> TryFrom<&'a str> for WindowsComponent<'a>
impl<'a> TryFrom<&'a str> for WindowsComponent<'a>
sourceimpl<'a> TryFrom<Component<'a>> for WindowsComponent<'a>
impl<'a> TryFrom<Component<'a>> for WindowsComponent<'a>
sourcefn try_from(component: StdComponent<'a>) -> Result<Self, Self::Error>
fn try_from(component: StdComponent<'a>) -> Result<Self, Self::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::windows::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.
sourceimpl<'a> TryFrom<WindowsComponent<'a>> for StdComponent<'a>
impl<'a> TryFrom<WindowsComponent<'a>> for StdComponent<'a>
sourcefn try_from(component: WindowsComponent<'a>) -> Result<Self, Self::Error>
fn try_from(component: WindowsComponent<'a>) -> Result<Self, Self::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::windows::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.
type Error = WindowsComponent<'a>
type Error = WindowsComponent<'a>
The type returned in the event of a conversion error.
impl<'a> Copy for WindowsComponent<'a>
impl<'a> Eq for WindowsComponent<'a>
impl<'a> StructuralEq for WindowsComponent<'a>
impl<'a> StructuralPartialEq for WindowsComponent<'a>
Auto Trait Implementations
impl<'a> RefUnwindSafe for WindowsComponent<'a>
impl<'a> Send for WindowsComponent<'a>
impl<'a> Sync for WindowsComponent<'a>
impl<'a> Unpin for WindowsComponent<'a>
impl<'a> UnwindSafe for WindowsComponent<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more