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§

source§

impl<'a> WindowsComponent<'a>

source

pub fn as_path<T>(&self) -> &Path<T>where T: for<'enc> Encoding<'enc>,

Returns path representing this specific component

source

pub fn is_prefix(&self) -> bool

Returns true if represents a prefix

source

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

source

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§

source§

impl AsRef<[u8]> for WindowsComponent<'_>

source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T> AsRef<Path<T>> for WindowsComponent<'_>where T: for<'enc> Encoding<'enc>,

source§

fn as_ref(&self) -> &Path<T>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'a> Clone for WindowsComponent<'a>

source§

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

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Component<'a> for WindowsComponent<'a>

source§

fn as_bytes(&self) -> &'a [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(),
]);
source§

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());
source§

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());
source§

fn len(&self) -> usize

Returns size of component in bytes
source§

fn is_empty(&self) -> bool

Returns true if component represents an empty byte slice
source§

impl<'a> Debug for WindowsComponent<'a>

source§

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

Formats the value using the given formatter. Read more
source§

impl<'a> Hash for WindowsComponent<'a>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a> Ord for WindowsComponent<'a>

source§

fn cmp(&self, other: &WindowsComponent<'a>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl<'a> PartialEq<WindowsComponent<'a>> for WindowsComponent<'a>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialOrd<WindowsComponent<'a>> for WindowsComponent<'a>

source§

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 · source§

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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
source§

impl<'a> TryFrom<&'a [u8]> for WindowsComponent<'a>

source§

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());
§

type Error = &'static str

The type returned in the event of a conversion error.
source§

impl<'a, const N: usize> TryFrom<&'a [u8; N]> for WindowsComponent<'a>

§

type Error = &'static str

The type returned in the event of a conversion error.
source§

fn try_from(path: &'a [u8; N]) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a str> for WindowsComponent<'a>

§

type Error = &'static str

The type returned in the event of a conversion error.
source§

fn try_from(path: &'a str) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<Component<'a>> for WindowsComponent<'a>

source§

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.

§

type Error = Component<'a>

The type returned in the event of a conversion error.
source§

impl<'a> TryFrom<WindowsComponent<'a>> for StdComponent<'a>

source§

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>

The type returned in the event of a conversion error.
source§

impl<'a> Copy for WindowsComponent<'a>

source§

impl<'a> Eq for WindowsComponent<'a>

source§

impl<'a> StructuralEq for WindowsComponent<'a>

source§

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.