Struct PrefixComponent

pub struct PrefixComponent<'a> { pub(in ::path) raw: &'a OsStr, pub(in ::path) parsed: Prefix<'a> }

A structure wrapping a Windows path prefix as well as its unparsed string representation.

In addition to the parsed Prefix information returned by kind, PrefixComponent also holds the raw and unparsed OsStr slice, returned by as_os_str.

Instances of this struct can be obtained by matching against the Prefix variant on Component.

Does not occur on Unix.

Examples

# if cfg!(windows) {
use std::path::{Component, Path, Prefix};
use std::ffi::OsStr;

let path = Path::new(r"c:\you\later\");
match path.components().next().unwrap() {
    Component::Prefix(prefix_component) => {
        assert_eq!(Prefix::Disk(b'C'), prefix_component.kind());
        assert_eq!(OsStr::new("c:"), prefix_component.as_os_str());
    }
    _ => unreachable!(),
}
# }

Fields

raw: &'a OsStr

The prefix as an unparsed OsStr slice.

parsed: Prefix<'a>

The parsed prefix data.

Implementations

impl<'a> PrefixComponent<'a>

fn kind(&self) -> Prefix<'a>

Returns the parsed prefix data.

See Prefix's documentation for more information on the different kinds of prefixes.

fn as_os_str(&self) -> &'a OsStr

Returns the raw OsStr slice for this prefix.

Trait Implementations

impl Hash for PrefixComponent<'_>

fn hash<H: Hasher>(&self, h: &mut H)

impl Ord for PrefixComponent<'_>

fn cmp(&self, other: &Self) -> Ordering

impl<'a> Clone for PrefixComponent<'a>

fn clone(&self) -> Self

impl<'a> Copy for PrefixComponent<'a>

impl<'a> Debug for PrefixComponent<'a>

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

impl<'a> Eq for PrefixComponent<'a>

fn assert_fields_are_eq(&self)

impl<'a> PartialEq for PrefixComponent<'a>

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

impl<'a> PartialOrd for PrefixComponent<'a>

fn partial_cmp(&self, other: &PrefixComponent<'a>) -> Option<Ordering>

impl<'a> TrivialClone for PrefixComponent<'a>

Auto Trait Implementations

impl<'a> Freeze for PrefixComponent<'a>

impl<'a> RefUnwindSafe for PrefixComponent<'a>

impl<'a> Send for PrefixComponent<'a>

impl<'a> Sync for PrefixComponent<'a>

impl<'a> Unpin for PrefixComponent<'a>

impl<'a> UnsafeUnpin for PrefixComponent<'a>

impl<'a> UnwindSafe for PrefixComponent<'a>

Blanket Implementations

impl<T> Any for PrefixComponent<'a> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for PrefixComponent<'a> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for PrefixComponent<'a> where T: ?Sized,

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

impl<T> CloneToUninit for PrefixComponent<'a> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for PrefixComponent<'a>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Printable for PrefixComponent<'a> where T: Copy + Debug,

impl<T> SizeHint for PrefixComponent<'a> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for PrefixComponent<'a>

impl<T> ToOwned for PrefixComponent<'a> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for PrefixComponent<'a> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom<U> for PrefixComponent<'a> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for PrefixComponent<'a> where U: TryFrom<T>,

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