Struct typed_path::windows::WindowsPrefixComponent
source · pub struct WindowsPrefixComponent<'a> { /* private fields */ }
Expand description
A structure wrapping a Windows path prefix as well as its unparsed string
representation. Byte slice version of std::path::PrefixComponent
.
In addition to the parsed WindowsPrefix
information returned by kind
,
WindowsPrefixComponent
also holds the raw and unparsed [[u8]
] slice,
returned by as_bytes
.
Instances of this struct
can be obtained by matching against the
WindowsPrefix
variant on WindowsComponent
.
This is available for use on all platforms despite being a Windows-specific format.
Examples
use typed_path::{WindowsPath, windows::{WindowsComponent, WindowsPrefix}};
let path = WindowsPath::new(r"c:\you\later\");
match path.components().next().unwrap() {
WindowsComponent::Prefix(prefix_component) => {
// Notice that the disk kind uses an uppercase letter, but the raw slice
// underneath has a lowercase drive letter
assert_eq!(WindowsPrefix::Disk(b'C'), prefix_component.kind());
assert_eq!(b"c:".as_slice(), prefix_component.as_bytes());
}
_ => unreachable!(),
}
Implementations§
source§impl<'a> WindowsPrefixComponent<'a>
impl<'a> WindowsPrefixComponent<'a>
sourcepub fn kind(&self) -> WindowsPrefix<'a>
pub fn kind(&self) -> WindowsPrefix<'a>
Returns the parsed prefix data
See WindowsPrefix
’s documentation for more information on the different
kinds of prefixes.
sourcepub fn as_bytes(&self) -> &'a [u8] ⓘ
pub fn as_bytes(&self) -> &'a [u8] ⓘ
Returns the raw [[u8]
] slice for this prefix
Examples
use typed_path::windows::WindowsPrefixComponent;
use std::convert::TryFrom;
// Disk will include the drive letter and :
let component = WindowsPrefixComponent::try_from(b"C:").unwrap();
assert_eq!(component.as_bytes(), b"C:");
// UNC will include server & share
let component = WindowsPrefixComponent::try_from(br"\\server\share").unwrap();
assert_eq!(component.as_bytes(), br"\\server\share");
// Device NS will include device
let component = WindowsPrefixComponent::try_from(br"\\.\BrainInterface").unwrap();
assert_eq!(component.as_bytes(), br"\\.\BrainInterface");
// Verbatim will include component
let component = WindowsPrefixComponent::try_from(br"\\?\pictures").unwrap();
assert_eq!(component.as_bytes(), br"\\?\pictures");
// Verbatim UNC will include server & share
let component = WindowsPrefixComponent::try_from(br"\\?\UNC\server\share").unwrap();
assert_eq!(component.as_bytes(), br"\\?\UNC\server\share");
// Verbatim disk will include drive letter and :
let component = WindowsPrefixComponent::try_from(br"\\?\C:").unwrap();
assert_eq!(component.as_bytes(), br"\\?\C:");
Trait Implementations§
source§impl<'a> Clone for WindowsPrefixComponent<'a>
impl<'a> Clone for WindowsPrefixComponent<'a>
source§fn clone(&self) -> WindowsPrefixComponent<'a>
fn clone(&self) -> WindowsPrefixComponent<'a>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<'a> Debug for WindowsPrefixComponent<'a>
impl<'a> Debug for WindowsPrefixComponent<'a>
source§impl Hash for WindowsPrefixComponent<'_>
impl Hash for WindowsPrefixComponent<'_>
source§impl Ord for WindowsPrefixComponent<'_>
impl Ord for WindowsPrefixComponent<'_>
source§impl<'a> PartialEq<WindowsPrefixComponent<'a>> for WindowsPrefixComponent<'a>
impl<'a> PartialEq<WindowsPrefixComponent<'a>> for WindowsPrefixComponent<'a>
source§fn eq(&self, other: &WindowsPrefixComponent<'a>) -> bool
fn eq(&self, other: &WindowsPrefixComponent<'a>) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl<'a> PartialOrd<WindowsPrefixComponent<'a>> for WindowsPrefixComponent<'a>
impl<'a> PartialOrd<WindowsPrefixComponent<'a>> for WindowsPrefixComponent<'a>
source§fn partial_cmp(&self, other: &WindowsPrefixComponent<'a>) -> Option<Ordering>
fn partial_cmp(&self, other: &WindowsPrefixComponent<'a>) -> Option<Ordering>
1.0.0 · source§fn 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 moresource§impl<'a> TryFrom<&'a [u8]> for WindowsPrefixComponent<'a>
impl<'a> TryFrom<&'a [u8]> for WindowsPrefixComponent<'a>
source§fn 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 WindowsPrefixComponent
Examples
use typed_path::windows::{WindowsPrefix, WindowsPrefixComponent};
use std::convert::TryFrom;
let component = WindowsPrefixComponent::try_from(b"C:").unwrap();
assert_eq!(component.kind(), WindowsPrefix::Disk(b'C'));
let component = WindowsPrefixComponent::try_from(br"\\.\BrainInterface").unwrap();
assert_eq!(component.kind(), WindowsPrefix::DeviceNS(b"BrainInterface"));
let component = WindowsPrefixComponent::try_from(br"\\server\share").unwrap();
assert_eq!(component.kind(), WindowsPrefix::UNC(b"server", b"share"));
let component = WindowsPrefixComponent::try_from(br"\\?\UNC\server\share").unwrap();
assert_eq!(component.kind(), WindowsPrefix::VerbatimUNC(b"server", b"share"));
let component = WindowsPrefixComponent::try_from(br"\\?\C:").unwrap();
assert_eq!(component.kind(), WindowsPrefix::VerbatimDisk(b'C'));
let component = WindowsPrefixComponent::try_from(br"\\?\pictures").unwrap();
assert_eq!(component.kind(), WindowsPrefix::Verbatim(b"pictures"));
// Parsing something that is not a prefix will fail
assert!(WindowsPrefixComponent::try_from(b"hello").is_err());
// Parsing more than a prefix will fail
assert!(WindowsPrefixComponent::try_from(br"C:\path").is_err());