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§

Returns path representing this specific component

Returns true if represents a prefix

Converts from WindowsComponent to Option<WindowsPrefixComponent>

Converts self into an Option<WindowsPrefixComponent>, consuming self, and discarding if not a WindowsPrefixComponent

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§

Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

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(),
]);

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

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());
Returns size of component in bytes
Returns true if component represents an empty byte slice
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
The type returned in the event of a conversion error.
Performs the conversion.

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());
The type returned in the event of a conversion error.
The type returned in the event of a conversion error.
Performs the conversion.

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.

The type returned in the event of a conversion 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.

The type returned in the event of a conversion error.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.