pub enum TypedPath<'a> {
    Unix(&'a UnixPath),
    Windows(&'a WindowsPath),
}
Expand description

Represents a path with a known type that can be one of:

Variants§

§

Unix(&'a UnixPath)

§

Windows(&'a WindowsPath)

Implementations§

source§

impl<'a> TypedPath<'a>

source

pub fn new(s: &'a [u8]) -> Self

Creates a new typed path from a byte slice by determining if the path represents a Windows or Unix path. This is accomplished by first trying to parse as a Windows path. If the resulting path contains a prefix such as C: or begins with a \, it is assumed to be a WindowsPath; otherwise, the slice will be represented as a UnixPath.

Examples
use typed_path::TypedPath;

assert!(TypedPath::new(br#"C:\some\path\to\file.txt"#).is_windows());
assert!(TypedPath::new(br#"\some\path\to\file.txt"#).is_windows());
assert!(TypedPath::new(br#"/some/path/to/file.txt"#).is_unix());

// NOTE: If we don't start with a backslash, it's too difficult to
//       determine and we therefore just assume a Unix/POSIX path.
assert!(TypedPath::new(br#"some\path\to\file.txt"#).is_unix());
assert!(TypedPath::new(b"file.txt").is_unix());
assert!(TypedPath::new(b"").is_unix());
source

pub fn is_unix(&self) -> bool

Returns true if this path represents a Unix path.

source

pub fn is_windows(&self) -> bool

Returns true if this path represents a Windows path.

source

pub fn to_path_buf(&self) -> TypedPathBuf

Converts into a TypedPathBuf.

Trait Implementations§

source§

impl<'a> From<&'a [u8]> for TypedPath<'a>

source§

fn from(s: &'a [u8]) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a str> for TypedPath<'a>

source§

fn from(s: &'a str) -> Self

Converts to this type from the input type.
source§

impl TryAsRef<Path<UnixEncoding>> for TypedPath<'_>

source§

impl TryAsRef<Path<WindowsEncoding>> for TypedPath<'_>

source§

impl<'a> TryAsRef<Path> for TypedPath<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for TypedPath<'a>

§

impl<'a> Send for TypedPath<'a>

§

impl<'a> Sync for TypedPath<'a>

§

impl<'a> Unpin for TypedPath<'a>

§

impl<'a> UnwindSafe for TypedPath<'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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

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

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

Performs the conversion.